How to concurrently process the asynchronous jms q

2019-09-06 05:38发布

问题:

My JMS consumer produces any number of messages on a JMS queue during the day. As soon as a message arrives it goes to message listener. If in between I need some other message comes, it goes to another message listener does not wait for first one?

As per my understanding here I need to create two consumer(assume i want to process 2 message concurrently) each having its own session. Both consumer can use the same message listener. Right?

I am not sure if I can achieve it with single consumer but can I with multiple listeners?

something like this Single queue: concurrent message processing with multiple consumers

回答1:

Per the JMS documentation @bgth cites, multiple MessageListeners in a single session will not provide concurrency:

"The session used to create the message consumer serializes the execution of all message listeners registered with the session. At any time, only one of the session’s message listeners is running"

For concurrency, you need multiple sessions and multiple consumers in separate threads. You can reuse the same MessageListener in this case, but it must be threadsafe.



标签: java jms