Implementing Publish Subscribe using Spring Integration JMS in ActiveMQ

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:44:16

问题


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:

Producer side:

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

Consumer Side:

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

回答1:


You need to add

<int:publish-subscribe-channel id="jmsPubSubChannel" />

on the consumer side.

If the channel is not explicitly declared, it defaults to a direct channel with round robin semantics.

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.



来源:https://stackoverflow.com/questions/38643740/implementing-publish-subscribe-using-spring-integration-jms-in-activemq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!