This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Using Message Selectors

Message selectors allow you to filter specific messages using a selector string. The message consumer will then receive only messages whose headers and properties match the selector. There are different patterns that can be used in selector strings, 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.

Note that message selectors are not supported in a clustered setup of WSO2 Message Broker (WSO2 MB).

Using message headers as selector criteria

A message header contains a number of predefined fields that contain values that both clients and providers can use to identify and to route messages. See the list of supported message types and header fields in WSO2 MB.

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

Message HeaderSelector String Example
JMSDestinationJMSDestination=destqueue
JMSMessageID JMSMessageID=JMSMessageID
JMSTimestamp JMSTimestamp=1396370353826
JMSCorrelationID JMSCorrelationID='srilanka'
JMSReplyTo 
JMSType JMSType='AAAA'

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:

  • JMSDeliveryMode
  • JMSExpiration
  • JMSPriority
  • JMSRedelivered

Using message properties as selector criteria

If you need values in addition to those provided by the header fields, you can create and set properties for the messages. See the list of supported message types and header fields in WSO2 MB.

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

Some example selector patterns are listed below:

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

Creating a message selector subscription

The createConsumer and createDurableSubscriber methods allow you to specify a message selector as an argument when you create a message consumer.

You can create a message selector subscriber for a topic as shown in the example given below. Note that the nolocal parameter is set to 'false' as it is not supported by WSO2 MB. However, messages will be delivered to the subscriber irrespective of the nolocal parameter.

String messgeSelector="JMSType='AAAA'"; 
topicSession.createSubscriber(topic,messgeSelector,false)