问题描述
我已经使用ActiveMQ中Spring Integration API的PublishSubscribe渠道开发了生产者和消费者。我可以使用实现发布和接收消息,但是只有一个服务激活器以循环方式使用消息。我需要确定是否正确。以下是我的配置:
I have developed a producer and consumer using Spring Integration API's PublishSubscribe Channel in ActiveMQ. I could publish and receive the messages using the implementation but only one service-activator consuming the message in round-robin fashion. I need to make sure whether it is right. Below are my configurations:
生产者端:
<int:publish-subscribe-channel id="jmsPubSubChannel" />
<int-jms:outbound-channel-adapter channel="jmsPubSubChannel"
destination-name="${jms.topic.name}"
pub-sub-domain="true"
connection-factory="connectionFactory" />
<!-- Define the ActiveMQ connection factory -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="${jms.broker.url}"/>
<property name="userName" value="${jms.username}" />
<property name="password" value="${jms.password}" />
</bean>
消费者方面:
<jms:message-driven-channel-adapter id="messageDrivenAdapter"
channel="jmsPubSubChannel"
destination-name="${jms.topic.name}"
pub-sub-domain="true" />
<!-- Subscriber - offeringmsg -->
<int:service-activator id="offeringmsg1" input-channel="jmsPubSubChannel" ref="impl1" />
<int:service-activator id="offeringmsg2" input-channel="jmsPubSubChannel" ref="impl2" />
<bean id="impl1" class="com.intuit.imp.mql.MessageListenerImpl" />
<bean id="impl2" class="com.intuit.imp.mql.MessageListenerImpl2" />
<!-- Define the ActiveMQ connection factory -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="${jms.broker.url}"/>
<property name="userName" value="${jms.username}" />
<property name="password" value="${jms.password}" />
</bean>
推荐答案
您需要添加
<int:publish-subscribe-channel id="jmsPubSubChannel" />
在消费者方面。
如果
在生产者端,因为只有一个使用者(出站通道适配器),所以没有明确声明该通道,它默认为具有循环语义的直接通道。不需要在那里有发布/订阅频道。
On the producer side, since there's only one consumer (the outbound channel adapter), it doesn't need to be a pub/sub channel there.
这篇关于在ActiveMQ中使用Spring Integration JMS实现发布订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!