JMS provides support for applications to filter and categorize messages. When creating a message, properties can be set in the message. When creating a consumer, a selector string can be specified. A message is given to the consumer if and only if its selector, when applied to the message, evaluates to true.
Message selector string are boolean expressions defined using a subset of SQL92. It can contain literals, identifiers (specifying JMS built-in message properties as well as application specific properties), white space, and various operator. Please refer to the Concepts for additional details.
In the P2P model, message selectors are used to create a "view" on the queue. If a message is not selector by a particular consumer, the queue will retain the message for any other consumer that might be interested in said message. In other words, un-selected messages are re-assigned to other consumers.
In the pub/sub model, un-selected messages are thrown away. If the selector for a particular subscriber rejects the message, said message will never be available to this subscriber. Other subscribers on the same topic may of course receive the message, depending on their message selectors.
This section contains two examples that explore the P2P and pub/sub models a little further and uses message selectors.
A chat application allows people to exchange simple text messages. This example illustrates a simple chat application based on the pub/sub model where selectors are used to block certain people from sending messages to you.
A mail application is used to send mail messages to people who may be off-line when the message was sent. This example shows how to write a simple mail program using the P2P model, where selectors are used to decide which messages are for who.
Copyright © 2003, 2004 Novell, Inc. All rights reserved. Copyright © 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.