Show TOC

Procedure documentationUsing Message Selectors Locate this document in the navigation structure

 

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.

Syntax Syntax

  1. String selector;
    
    selector = new String("(name = 'searched_string') OR (name = 'another_searched_string')");
    
    
End of the code.
Creating a Message Consumer with Selector
  • When you use a Topic connection, you create the message consumer as follows:

    Syntax Syntax

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

    Syntax Syntax

    1. receiver = queueSession.createReceiver(queue, selector);
      
    End of the code.