Checking JMS type while reading messages asynchronously

935 Views Asked by At

I have a Queue in my JMS. While sending messages to the queue I am mentioning the JMStype as 'XYZ'. At the consumer end I have an onMessage listener. What I want to know is the following

  1. In onMessage listener how do I check for the JMStype of the message without dequeuing the message. If my running instance finds that the JMStype is not 'XYZ' then it should not do anything and should not dequeue it from my queue. Only the instance which needs a message of JMStype 'XYZ' should dequeue the message and process it further.

Thanks for your time to read my query.

1

There are 1 best solutions below

0
On BEST ANSWER

I would suggest using a message selector rather than JMSType for this purpose. Spring JMS message listeners lets you filter messages based on JMS properties as well as JMS headers.

When writing messages to queue you could set a message poperty as "type='abc'", on the listener's configuration you could look for certain "types" by providing a messageSelector="type='abc'".

This way only the messages matching the selectors are picked from the queue.