Question

I have a JMS queue implementation with JmsTemplate. I want to have more than one listener when a message is put in the queue, i.e. I want to use topic instead of queue.

I have configuration without JMS namespacing. What are the changes that need to be made to have multiple listeners listen on a topic when someone sends a message in a topic.

Was it helpful?

Solution

I guess you are probably using DefaultMessageListenerContainer. Just to be sure, you want that several individual components receive the same message (i.e. you don't want to process messages in parallel).

Assuming I got this right and component A and compoent B should receive the same message, you simply create two DefaultMessageListenerContainer instance on the same topic and you set the pubSubDomain property to true. Make sure you haven't set any concurrency on the listener container, or better yet, set the concurrency to 1 to make that explicit.

This would give something like

<bean id="listener1"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="pubSubDomain" value="true"/>
    <property name="concurrency" value="1"/>
    <property name="destinationName=" value="...."/> <!-- topic name -->
    <property name="messageListener" ref="...."/> 
</bean>

Then you should create a similar bean for the second component.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top