Question

I am using Spring JMS with ActiveMQ as the broker and running the application on Tomcat. I have seen many examples of receiving messages synchronously with a specified message selector using receiveSelected(..). But I cannot find any way to dynamically specify the message selector on a jms:listener-container to receive a message asynchronously. The selector will be known only at runtime.

The only way I can think of doing it is to use DefaultMessageListenerContainer instead and create a new instance every time I need a new selector. But I'm unsure if this is the right approach and the best practices in doing so. For example, should the listenerContainer associated with a selector be cached? When should it be shutdown etc.?

I would really appreciate it if someone could point me to an example or outline a strategy to handle this situation.

Thanks in advance!

Was it helpful?

Solution

You can't change the selector while the container is running (you can, but only new listener threads will use it). You can stop the container, modify the selector to include the new conditions, and start the container again.

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