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/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

Message headers

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. 

Following is a list 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

Message properties

If you need values in addition to those provided by the header fields, you can create and set properties for the messages.

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 in the following example:

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

When creating a subscriber, set the nolocal property to 'false' as this property is not supported by MB. However, messages are still delivered to the subscriber irrespective of the nolocal parameter.

  • No labels