• Post Reply Bookmark Topic Watch Topic
  • New Topic

jms: asynchrounous messages selected by ID  RSS feed

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could anyone please advise on a recommended way to register an *asyncrhounous* message listener, using a message selector that relies on *message id* ?
Posted a similar question on synchronious listeners, and it worked -thanks .However, with asynchronous mode, I'm having a race condition, because message ID is only known after you've sent it; by that time, it's too late to register the listener since it may missed the reply.

Code example:


Thank you very much for taking a look.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, correction. I was of course trying to listen for incoming messages with *correlation* id equals to the original request's *message* id, so the selector should be:

String selector="JMSCorrelationID=' + msg.getJmsMessageId() + "'";
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a hard time figuring out what you want. Why do you want to set up an asynchronous listener for one message? If you filter according to the correlation id, then why would you ever get more than one message in this queue? Are you expecting to destroy the listener after it gets its one message?

Sounds like instead you want to use a temporary queue and the reply-to-queue feature if you're only expecting one message back. In that case, just create a temporary queue, set the reply-to-queue property on your message (setJMSReplyTo) to be the temporary queue, and then create an asynchronous listener on the temporary queue. That way you don't have to mess with the correlation ID at all.

Kyle
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!