Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up Multiple Listeners for Multiple Queues on same thread and session  RSS feed

 
Ken Rubin
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is it possible and not uncustomary to set up a single session that listens on three different queues, as three message listeners? My understanding is that
each listener will share the thread.

Below is a fragment of code to setup 1 listener on a session. Is it true,
that I would create additional consumers and message listeners?

Thank you!!!

Ken

connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
replyQueue = session.createTemporaryQueue();
consumer = session.createConsumer(replyQueue);
consumer.setMessageListener(new HRListener());
connection.start();
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an inbound message scenario with a message listener the listener is invoked with a thread coming from the JMS server in contrast to the MessageConsumer.receive(). With your scenario you can receive concurrent messages (one by each lsitener) whereas with the MessageConsumer you can only retrieve one message at the time.

-Andy
 
Ken Rubin
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Andreas, this brings things into better focus.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!