简体   繁体   中英

Implementing Publish Subscribe using Spring Integration JMS in ActiveMQ

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM