Show TOC

Using Message SelectorsLocate this document in the navigation structure

Use

When your application design needs to filter messages, you can use the JMS message selectors. This allows the application to receive only those messages that contain specific information and ignore the rest. When you have messages that are sent to many clients, the message consumers can create selection criteria based on the message headers. Then the JMS provider can handle the filtration work instead of the application.

Procedure

Creating a Message Selector

You define the criteria for message selection of a particular consumer, specifying conditions on the values of the message properties, and using the message selector expression.

               String selector;

selector = new String("(name = 'searched_string') OR (name = 'another_searched_string')");
 

            

Creating a Message Consumer with Selector

  • When you use a Topic connection, you create the message consumer as follows:

                         subscriber = topicSession.createSubscriber(topic, selector);
    
                      
  • When you use a Queue connection, you create the message consumer as follows:

                         receiver = queueSession.createReceiver(queue, selector);