Home > Enterprise >  JMS Message Selectors - consuming everything else / catch all / default case
JMS Message Selectors - consuming everything else / catch all / default case

Time:03-15

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?

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.

CodePudding user response:

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.

  • Related