Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A message selector allows a JMS consumer to be more selective about the messages that it receives from a particular topic or queue. A message selector uses message properties and message headers as criteria in conditional expressions. These expressions use Boolean logic to declare the messages that are delivered to a client. The message consumer will only receive messages where the headers and properties match the selector. There are different patterns that can be used in selector strings to filter messages and the broker (JMS provider) filters messages according to that query. It is not possible for a message selector to filter messages on the basis of the content of the message body. See the list of supported message types and header fields in WSO2 MB.

...

The way selectors work depends on the type of subscription that is created from JMS clients. The following sections explain the different scenarios:

Queue subscriptions

  • Only messages that match the selector will be delivered to the subscriber. 
  • If at least one subscriber out of a few subscribers for a queue has a matching selector, the message will be delivered to that subscriber. 
  • If more than one subscriber has a matching selector, the messages will be delivered in round robin manner between those subscribers. 
  • If none of the subscribers have matching selectors, that message will be placed in the Dead Letter Channel (DLC).

...

  • Only messages that match the selector will be delivered to the durable topic subscriber. 
  • When keeping a copy of a message coming for a topic for the particular subscription ID, selectors are not evaluated. They are evaluated upon delivery only. 
  • If a message does not match with the selector for a particular durable topic subscription, it will be routed to the Dead Letter Channel (DLC). 

Messages routed to DLC

  • If none of the subscribers have matching selectors with a message and if the message is for a durable queue or durable subscription, the message is routed to the DLC.
  • User has the option to delete messages selectively if they are unnecessary. 
  • It is possible to create a new queue and route all unmatched messages to that queue if required. 
  • It is possible to create a new subscriber with a matching selector for some or all messages routed to the DLC and route all messages to the original queue again. Then, if there are newly created matching subscriptions, those messages will be delivered accordingly. Other messages will go to DLC queue once again. 

...

The following are examples of message header selector strings that are supported:

Message HeaderSelector String Example
JMSDestinationJMSDestination=destqueueJMSMessageID JMSMessageID=JMSMessageID
JMSTimestamp JMSTimestamp=1396370353826
JMSCorrelationID JMSCorrelationID='srilanka'
JMSReplyTo
 

JMSType JMSType='AAAA'

Note that the following two headers will be ignored by the broker when it is sent from the JMS client. Therefore, these need to be set at the broker level.

Message HeaderSelector String Example
JMSDestinationJMSDestination=destqueue
JMSMessageID JMSMessageID=JMSMessageID

The following message headers will not be filtered by the broker as they are handled by the JMS provider and the default values override the selector string:

...

The following is a list of message property selector strings that are supported:

Message PropertiesSelector String Example
BytePropertyByteMsgID=127
ShortPropertyShortMsgID=32,767
IntPropertyIntMsgID=400000000
LongPropertyLongMsgID=1212322222
FloatPropertyFloatMSgID = 0.0f
DoublePropertyDoubleMsgID = 20011111000.12120
StringPropertyStrMsgID='100'
BooleanPropertyBoolMsgID=false

ObjectProperty

 


Examples of selector patterns

Given below are some sample selector patterns.

Selector PatternsExample
Header='value' OR Header='value' JMSType='AAAA' OR JMSPriority=4
Property='value' AND Property='value'Country='SL' AND ID=1
Header='value' OR Property='value'JMSType='AAA' OR msgID='1'
Header='value' AND Property='value' AND Property='value' JMSType = 'AAA' AND color = 'red' AND weight= 3500
(Property='value' OR Header='value') AND Property='value' (Country='SL' OR JMSType='AAA') AND ID=1

...

Subscribing to topics/queues using selectors

...