0

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

Community
  • 1
  • 1
user3198603
  • 5,528
  • 13
  • 65
  • 125
  • If you have a consumer that is not context reliant you could instantiate one consumer and n listeners on threads that execute a single instance of the inantiated consumer. You'd need to make sure you code is thread safe though ... just a thought. – Travis Sharp Apr 06 '14 at 05:25
  • What is the difference between a consumer and a "message listener"? – lreeder Apr 06 '14 at 05:53
  • Please check the docs.. http://docs.oracle.com/cd/E19798-01/821-1841/bncep/index.html – bgth Apr 06 '14 at 06:44
  • @lreeder is my understanding correct. We have to create two consumer with separate session. Can do it with single consumer but with two sparate listener. Right? – user3198603 Apr 06 '14 at 07:01

1 Answers1

2

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.

lreeder
  • 12,047
  • 2
  • 56
  • 65