这是我今天提出的Spring Integration,如果您发现可以改进的地方,请跟进。
在客户端,可以通过 SimpleMessagingGateway 发送和接收消息:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<import resource="integration-common.xml"/>
<!-- Communication Gateway for the Client (send/receive) -->
<bean id="gateway" class="org.springframework.integration.gateway.SimpleMessagingGateway">
<property name="requestChannel" ref="SenderChannel"/>
<property name="replyChannel" ref="InboundChannel"/>
<property name="replyTimeout" value="1000"/>
</bean><!-- TODO: could use integration:gateway -->
<!-- Sending out message to JMS request queue -->
<integration:channel id="SenderChannel"/>
<jms:outbound-channel-adapter
channel="SenderChannel"
destination="requestQueue" />
<!-- Listen to incoming messages on JMS reply queue -->
<integration:channel id="InboundChannel">
<integration:queue/>
</integration:channel>
<jms:message-driven-channel-adapter
destination="replyQueue"
channel="InboundChannel" />
</beans>
处理节点端的配置如下所示(有关 Spring Integration 元素的更多解释,请参见内联注释):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<import resource="integration-common.xml"/>
<!-- Read in Message Endpoint Service Activator classes -->
<context:component-scan base-package="sample.integration.jmsbasic"/>
<!-- Listen to incoming messages on the JMS request queue -->
<integration:channel id="jmsinToProcChannel"/>
<jms:message-driven-channel-adapter
destination="requestQueue"
channel="jmsinToProcChannel"/>
<!-- Delegate message to service implementation and take care of answer -->
<integration:service-activator
input-channel="jmsinToProcChannel"
ref="procService"
output-channel="jmsBackChannel" />
<!-- Send answer back to JMS reply queue -->
<integration:channel id="jmsBackChannel"/>
<jms:outbound-channel-adapter
channel="jmsBackChannel"
destination="replyQueue" />
</beans>