Question

I am using ActiveMQ with Spring. It is easy to configure and start listening to messages.

One of my queues is defined as

<jms:listener-container container-type="default" 
                        connection-factory="connectionFactory"
                        acknowledge="auto">
    <jms:listener destination="RV_QUEUE" ref="webListener" />
</jms:listener-container>

All is good, but I would like to dynamically make some of the machines in our nodes to unregister themselves from ActiveMQ, in order to stop consuming messages.

I can make every machine listen for a signal. The question is, how can I make them register/unregister with AMQ?

Would I need to go back to creating my own sessions, and opening and closing them? Or is there a Spring way of doing it?

Was it helpful?

Solution

The <jms:listener-container> populates AbstractJmsListeningContainer beans for each <jms:listener> sub-element configuration. That container may be registered with explicit id.

From other side the AbstractJmsListeningContainer implements SmartLifecycle. So you can start/stop any Listener Container (with its Listener) any time by that id attribute:

beanFactory.getBean("myListener", Lifecycle.class).stop();

After stopping of the Listener Container, your Listener stops to consume messages from queue.

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