7.6 Selecting the received messages using Message Selector

The consumer can select the messages it wants to receive by using Message Selector. The consumers that use Message Selector can receive only the necessary messages from the messages registered in the destination.

With Message Selector, you use the message property values to specify the messages to be selected. The consumer compares the selection conditions specified in Message Selector and the values of the message properties, and receives only those messages that match the conditions.

The following figure provides an overview of selecting the received messages using Message Selector.

Figure 7-8 Overview of selecting the received messages using Message Selector

[Figure]

In this figure, the select condition 'Color=red' is specified for consumer2. Message Selector is not specified for consumer1.

When the producer sends four messages with different Color properties, consumer1 that does not use Message Selector receives all the messages. Consumer2 only receives two messages that match the selection conditions.

Note that you specify the selection conditions of Message Selector using the Message-driven Bean attributes operated in the consumer, or the JMS APIs. For details on the attributes, see 7.12 Definitions in the DD. Also, for details on the syntax and APIs of the selection conditions, see the JMS specifications.

Reference note
You can also use Message Selector with a queue browser.