O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The following is a list of the nine JMS-defined properties, which are described in more<br />
detail in Appendix C:<br />
• JMSXUserID<br />
• JMSXAppID<br />
• JMSXProducerTXID<br />
• JMSXConsumerTXID<br />
• JMSXRcvTimestamp<br />
• JMSXDeliveryCount<br />
• JMSXState<br />
• JMSXGroupID<br />
• JMSXGroupSeq<br />
3.2.3 Provider-Specific Properties<br />
Every JMS provider can define a set of proprietary properties that can be set by the client<br />
or the provider automatically. Provider-specific properties must start with the prefix<br />
"JMS_" followed by the property name (JMS_). The purpose of the<br />
provider-specific properties is to support proprietary vendor features.<br />
3.3 <strong>Message</strong> Selectors<br />
A message selector allows a JMS consumer to be more selective about the messages it<br />
receives from a particular destination (topic or queue). <strong>Message</strong> selectors use message<br />
properties and headers as criteria in conditional expressions. These conditional expressions<br />
use boolean logic to declare which messages should be delivered to a JMS consumer.<br />
For example, in the chat client developed in Chapter 2, message selectors could be used to<br />
filter out messages from specific people. To accomplish this we would first declare a new<br />
property in the message that identifies the username of the JMS client publishing the<br />
message:<br />
protected void write<strong>Message</strong>(String text) throws JMSException{<br />
Text<strong>Message</strong> message = session.createText<strong>Message</strong>( );<br />
message.setText(text);<br />
message.setStringProperty("username",username);<br />
publisher.publish(message);<br />
}<br />
JMS clients can now use that property to filter messages. <strong>Message</strong> selectors are declared<br />
when the message consumer is created:<br />
TopicSubscriber subscriber =<br />
session.createSubscriber(chatTopic, " username != 'William' ",false);<br />
In this code, the message selector (shown in bold) tells the message server to deliver to the<br />
consumer only those messages that do not have a username property equal to 'William'.<br />
The message selectors are based on a subset of the SQL-92 conditional expression syntax,<br />
which is used in the WHERE clauses of SQL statements. If you are familiar with SQL 92,<br />
the conditional expressions used in message selectors will be familiar to you. The syntax<br />
used for conditional expressions is covered in detail in Appendix D.<br />
40