Sunday, 5 August 2018

JMS: Message Selectors in detail

Message selectors are used to filter the messages. A JMS message selector allows a client to specify the messages that it’s interested in. Only messages whose headers and properties match the selector are delivered to the client.

This is continuation to my previous post, if you would like to see an example on message selectors, I would recommend you go through my previous post.

For example,
There is an order processing queue in an organization.
Consumer 'C1' is interested in processing orders of <= 100$.
Consumer 'C2' is interested in processing orders of > 100$ & < 1000$
Consumer 'C3' is interested in processing orders of >= 1000$.

By specifying the selection criteria at the time of consumer creation, consumer will receive the messages that he interested in. JMS provider (like ActiveMQ) filter these messages and send only the messages that consumer is interested in.

Ex
MessageConsumer C3 = session.createConsumer(destination, "orderCost >= 1000");

Syntax of Message Selector
Message selector syntax is based on SQL92 conditional expression syntax.

Points to consider while working with message selectors.
a.   If the value of a message selector is an empty string, the value is treated as a null and indicates that there is no message selector for the message consumer.
b.   The order of evaluation of a message selector is from left to right within precedence level. Parentheses can be used to change this order.
c.   Date and time values should use the standard Java long millisecond value.
d.   SQL Comments are not supported
e.   Although SQL supports fixed decimal comparison and arithmetic, JMS message selectors do not.

Examples
a.   "age BETWEEN 15 AND 19"
b.   "age >= 15 AND age <= 19"
c.   "age NOT BETWEEN 15 AND 19"
d.   "age < 15 OR age > 19"
e.   "Country IN ('UK', 'US', 'France')"
f.    "(Country = 'UK') OR (Country = 'US') OR (Country = 'France')"
g.   "Country NOT IN ('UK', 'US', 'France')"
h.   "NOT ((Country = 'UK') OR (Country = 'US') OR (Country = 'France'))"
i.     "phone LIKE '12%3'"
j.    "word LIKE 'l_se'"
k.   "underscored LIKE '\_%'
l.     "phone NOT LIKE '12%3'"
m. "prop_name IS NULL"
n.   "prop_name IS NOT NULL"
o.   "JMSType = 'car' AND color = 'blue' AND weight > 2500"




Previous                                                 Next                                                 Home

No comments:

Post a Comment