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
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.
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
AND has higher precedence than ...