Appendix E. JMS Message Selector Syntax

JMS message selectors are used by JMS clients to filter the messages that a JMS server delivers to a given MessageConsumer. A message selector is provided (optionally) when a MessageConsumer is created, using either the QueueSession. createReceiver() or the TopicSession.createSubscriber() method.

A message selector is a string that specifies a predicate to be applied to each message that the provider wants to deliver to a MessageConsumer. If the predicate evaluates to true, then the message is delivered; if false, then the message is not delivered. In point-to-point messaging, when messages are filtered out by a message selector, the message will remain on the queue until the client eventually reads it or the message times out and the server removes it from the queue. In publish-subscribe messaging, messages that are filtered are never delivered to the subscriber.

In this chapter, we provide the full syntax of JMS message selectors. For more details on using JMS in general, see the tutorial in Chapter 11.

Structure of a Selector

A message selector is made up of one or more Boolean expressions, joined together by logical operators and grouped using parentheses. For example:

(<expression1> OR <expression2> AND <expression3>) OR

    (<expression4> AND NOT <expression5>) . . .

A message selector is evaluated left to right in precedence order. So in this example, expression2 will be evaluated followed by expression3 (since AND has higher precedence than ...

Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.