2
votes

I'm working with Spring, JMS, ActiveMQ. I have a DefaultMessageListenerContainer with empty destination name. I also have a listener. As you know, a listener container can have many listeners for different destinations as shown below:

<jms:listener-container
    container-type="default"
    connection-factory="jmsConnectionFactory"
    acknowledge="auto" >
        <jms:listener destination="TEST.FOO" ref="myMessageListener" method="onMessage" />
        <jms:listener destination="foo.bas" ref="myMessageListener" method="onMessage" />
        <jms:listener destination="foo.bar" ref="myMessageListener" method="onMessage" />                
</jms:listener-container>

In the above configuration, I am specifying the destinations in advance. But, I want to configure destinations dynamically. Could you please tell me how? Thanks!

1
Do you mean you want to pick destination names dynamically, or you want to resolve the fixed names to dynamic destinations?skaffman
I've many queues on ActiveMQ. I don't want to configure a listener for them in the configuration XML. I want to dynamically able to pick the destination names when the listener is alerted of a message.Faisal

1 Answers

3
votes

If you send a message to an ActiveMQ queue that is not currently defined, it creates a queue for you with the given name.

This site walks you through how to dynamically setup listeners for the dynamic queues that are generated. The example uses RabbitMQ, but you can replace the rabbitMQ connection factory with an ActiveMQ factory and replace the RabbitTemplate with a JMSTemplate. Everything else should be the same. The example does everything in code, but you can easily move the logic into your spring config.