This documentation is for WSO2 Message Broker 3.0.0. View documentation for the latest release.
Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
Skip to end of metadata
Go to start of metadata

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
JMSMessageID JMSMessageID=JMSMessageID
JMSTimestamp JMSTimestamp=1396370353826
JMSCorrelationID JMSCorrelationID='srilanka'

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
FloatPropertyFloatMSgID = 0.0f
DoublePropertyDoubleMsgID = 20011111000.12120



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'"; 
  • No labels