O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required