0

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>
atr
  • 684
  • 6
  • 10

1 Answers1

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks. If on producer side I need to add more consumers then what needs to be added. – atr Jul 28 '16 at 18:34
  • I don't understand the question; from a Spring Integration perspective the only consumer on that channel is the outbound channel adapter. If you need to send it to multiple topics then leave it as a pub sub channel and add an adapter for each topic. – Gary Russell Jul 28 '16 at 18:45
  • Sorry my wrong. Tested my adding one more adapter in Producer side to send to another topic. Changed to publish-subscribe-channel in consumer side made both the service-activator to consume the messages. Worked perfectly. Great. Thanks again. – atr Jul 28 '16 at 19:22
  • Great - it's customary here to "accept" the answer (click the tick/check mark below the vote buttons) if it answers your question - it will help others searching for answers. Thanks! – Gary Russell Jul 28 '16 at 19:38