我想将JMS添加到现有的spring集成项目中。我想要更改的xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:int-http="http://www.springframework.org/schema/integration/http" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd">
<channel id="eventUpdateChannel" />
<chain input-channel="eventUpdateChannel" output-channel="eventUpdateChannelRouter">
(...)
</chain>
(...)
</bean>
这样就可以了,处理通过eventUpdateChannel
传来的消息。
在查看Spring Integration站点中的示例后,我将该xml文件更改为:
(...)
<channel id="eventUpdateChannel" />
<channel id="jmsEventUpdateChannel" />
<jms:message-driven-channel-adapter id="jmsIn" destination="inboundMessageQueue" channel="eventUpdateChannel" />
<jms:outbound-channel-adapter id="jmsOut" channel="jmsEventUpdateChannel" destination="inboundMessageQueue"/>
<chain input-channel="jmsEventUpdateChannel" output-channel="eventUpdateChannelRouter">
(...)
我也添加了这部分:
<!-- JMS -->
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="inboundMessageQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="queue.request"/>
</bean>
现在,应用程序启动后,当收到消息时,消息未处理,我收到此警告:
org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel eventUpdateChannel.
答案 0 :(得分:1)
您的适配器正在将其数据发送到eventUpdateChannel
,而<chain/>
已不再订阅任何内容。
之前,<channel id="eventUpdateChannel" />
<jms:outbound-channel-adapter id="jmsOut" channel="eventUpdateChannel" destination="inboundMessageQueue"/>
<jms:message-driven-channel-adapter id="jmsIn" destination="inboundMessageQueue" channel="jmsEventUpdateChannel" />
<channel id="jmsEventUpdateChannel" />
<chain input-channel="jmsEventUpdateChannel" output-channel="eventUpdateChannelRouter">
订阅了它。
根据您的评论,您需要
eventUpdateChannel
如果您正在使用JMS进行持久化,则可以删除适配器并简单地使{{1}}成为jms支持的通道。如果您使用它将工作分发给其他JVM,那么适配器是正确的选择。