Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JMS Message Selectors – consuming everything else / catch all / default case

Suppose I have a single queue. I have 3 consumers reading from that queue with the following selectors:

    consumer1: myMessageType = 'Funny'
    consumer2: myMessageType = 'Sad'
    consumer3: no selector defined

Now I send a bunch of messages in the queue like this…

    Message 1 : myMessageType = 'Funny'
    Message 2 : myMessageType = 'Funny'
    Message 3 : myMessageType = 'Funny'
    Message 4 : myMessageType = 'Funny'
    Message 5 : myMessageType = 'Sad'
    Message 6 : myMessageType = 'Sad'
    Message 7 : myMessageType = 'Sad'
    Message 8 : myMessageType = 'Sad'
    Message 9 : myMessageType = 'Weird'
    Message 10: myMessageType = 'Weird'
    Message 11: myMessageType = 'Weird'
    Message 12: myMessageType = 'Weird'

Will consumer3, with no message selector defined, only receive messages where myMessageType = ‘Weird’? Or will consumer3 receive all the message types?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve obviously simplified my question from our real world use case. We’ll have many consumers with message selectors and are trying to figure out if we can use a consumer with no message selector to handle every message that doesn’t match the selectors of any other consumer.

I’ve searched and have been unable to find a definitive answer to this question. I thought about writing some code to test it but worry that many variables under the covers (prefetch, caching, concurrency, etc) might give me a misleading result. Lastly I’m also concerned the behavior might be different from broker to broker if not explicitly specified in the specification. I’m hoping someone might know the concrete answer.

>Solution :

A JMS consumer without a selector can receive any message, regardless of what selectors other consumers are using. Therefore, to get the behavior you want you need to create an "opposite" selector, as you described, for any message that doesn’t match.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading