7. Message Selectors

This section discusses the following topics.

Message Selection provides a way to filter messages at the consumer side utilizing message properties. A message selector is an SQL92-compliant expression that guides a consumer to reject the message if it is not a match.

At the time of consumer creation, an application passes the message selector string to JMS. As messages arrive, the consumer compares their header and properties information to the message selector and rejects messages that evaluate false. For example, a message selector "MyProp > 5" allows consumers to receive messages whose JMS message header field MyProp value is greater than 5.

7.1. Publish/Subscribe

In the publish/subscribe scenario, you can have many consumers subscribed to the same topic, but use message selectors to filter out selected consumers, and hence, selected receiving clients and applications. In this scenario, each consumer decides whether or not to discard the message.

Figure 8. Message selectors, publish/subscribe

For example, to create a topic subscriber with a message selector for consuming messages with one property greater than 5 and another property equal to 3:

// Create a selector to receive only messages with MyProp1 greater than 5 and MyProp2 equal to 3.
String selector = "MyProp1 > 5 AND MyProp2 = 3";

// Create a topic subscriber using the selector.
TopicSubscriber topicSubscriber = topicSession.createSubscriber(queue, selector);
   

7.2. Point-To-Point

In the point-to-point scenario, you can employ message selectors at the queue to determine which of multiple consumers to send messages to. To ensure once-and-only-once delivery, the queue typically ensures that only the consumer assigned per message selector consumes a given message.

Figure 9. Message selectors, point-to-point

For example, to create a queue receiver with a message selector for consuming messages with one property greater than 5 and another property equal to 3:

// Create a selector to receive only text messages with MyProp greater than 5.
String selector = "MyProp1 > 5 AND MyProp2 = 3";

// Create a queue receiver using the selector.
QueueReceiver queueReceiver = queueSession.createReceiver(queue, selector);
   

If a consumer is not available for a particular filtered message, the queue skips and retains this message, and then continues processing subsequent messages.

When you configure a queuing application to use application sets, the message selectors can target individual consumers in an application set. Application sets essentially split consumers into logical queues so that the desired once-and-only-once message delivery behavior applies to all consumers inside them. A consumer in one application set can receive the same message as a consumer in another. Message selectors in different application sets let the queue assign messages to selected consumers within the same application set.

7.3. Native Applications

You can use message selectors at the native provider level (i.e., UM sources or receivers written in C, Java, or .NET). Message selectors can work in the native application scenarios listed below.

JMS Producer to UM Receiver - Set option message_selector to the desired message selector string when creating the consumer. This string must follow SQL92 syntax as described in the JMS Specification, for example "MyProp1 = 6 AND MyProp2 < 7". See also Ultra Messaging JMS Options.

UM Source to JMS Consumer - Set message properties so that the name matches that used by the JMS consumer's message selector.

UM Source to UM Receiver - You can use the message selector feature outside of the JMS environment by setting message properties at the UM source, and the message_selector option at the UM receiver.

Note: For a UM receiver, used with UMP, and with an event queue or if retaining/promoting messages outside of the receiver callback function, we recommended you enable either explicit ACK'ing (ume_explicit_ack_only), or ACK batching (ume_use_ack_batching). This prevents undesired/unwarranted ACKs for messages still waiting to be processed.

Copyright (c) 2004 - 2014 Informatica Corporation. All rights reserved.