3

我想将 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.
4

1 回答 1

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">

如果您所做的只是使用 JMS 进行持久性,您可以删除适配器并简单地创建eventUpdateChannel一个 jms 支持的通道。如果您使用它将工作分配给其他 JVM,那么适配器是正确的选择。

于 2013-08-14T15:46:44.500 回答