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.
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
String selector; selector = new String("(name = 'searched_string') OR (name = 'another_searched_string')");
When you use a Topic connection, you create the message consumer as follows:
Syntax
subscriber = topicSession.createSubscriber(topic, selector);
When you use a Queue connection, you create the message consumer as follows:
Syntax
receiver = queueSession.createReceiver(queue, selector);