0
votes

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

1 Answers

1
votes

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.