views:

2195

answers:

2

Hi, I'm new to JMS and I am working on setting up ActiveMQ with Tomcat 6 and Spring. I have most of the basic things configured however I'm a little bit confused with the Message Listener Containers that Spring provides. Reading the documentation it sounds like the Message Listener Container is used to "handle" subscribing (I'm working with Topics), unsubscribing and delivering the message to the listener. I not sure if I'm thinking about this correctly. If this is the case I don't see any documentation on how I would have multiple classes subscribe to the same topic using the Message Listener Container. I see that you can set the messageListener property but that would only allow one class to be able to subscribe to a topic. It doesn't seem right to create another instance of the same Message Listener Container just to have another subscriber (Message Driven POJO) listen to the same topic.

Can anyone shed some light on this for me? I think I may be a little confused.

Thanks in advance!

A: 

The container is a wrapper of sorts to "adapt" any POJO to receiving messages from a Queue or Topic. If you desire multiple listeners, you will end up with multiple containers.

+1  A: 

If you're familiar with Message-Driven EJBs, then a Spring MessageListenerContainer is effectively replacement for an MDB. It gets its name because it's wired up with the JMS topic/queue, as well as a single JMS MessageListener, and it pulls messages off that topic/queue and feeds them to your MessageListener.

You're quite right that only one MessageListener can be registered with each container at a time, but consider that while the MessageListenerContainer code can be quite complex, it's actually a very lightweight runtime component. Don't be afraid to create several instances of it.

Also, make sure you pick the appropriate MessageListener implementation for your situation. The Simple and Default implementation are really quite different, but neither is "better".

skaffman