23.07.2013 Views

O'Reilly - Java Message Service

O'Reilly - Java Message Service

O'Reilly - Java Message Service

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix D. <strong>Message</strong> Selectors<br />

<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />

<strong>Message</strong> selectors allow a JMS consumer to be more selective about the messages it<br />

receives from a particular topic or queue. <strong>Message</strong> selectors use <strong>Message</strong> properties and<br />

headers as criteria in conditional expressions. These conditional expressions use boolean<br />

logic to declare which messages should be delivered to a client.<br />

The message selectors are based on a subset of the SQL-92 conditional expression syntax<br />

that is used in the WHERE clauses of SQL statements. This section is a detailed exploration<br />

of the message selector syntax.<br />

To illustrate how message selectors are applied, we will consider a hypothetical message<br />

that contains three application properties: Age, Weight, and LName. Age is an int, Weight is a<br />

double, and LName is a String property. The values of these properties depend on the<br />

message. The message selector is used to obtain only those messages with property values<br />

of interest to the consumer.<br />

D.1 Identifiers<br />

An identifier is the part of the expression that is being compared. For example, the<br />

identifiers in the following expression are Age, Weight, and LName:<br />

Age < 30 AND Weight >= 100.00 AND LName = 'Smith'<br />

Identifiers can be any application-defined, JMS-defined, or provider-specific property, or<br />

one of several JMS headers. Identifiers must match the property or JMS header name<br />

exactly; identifiers are case sensitive. Identifiers have the same naming restrictions as<br />

property names (see Appendix C).<br />

The JMS headers that can be used as identifiers include JMSDeliveryMode, JMSPriority,<br />

JMS<strong>Message</strong>ID, JMSTimestamp, JMSCorrelationID, and JMSType. The JMSDestination and<br />

JMSReplyTo headers cannot be used as identifiers because their corresponding values are<br />

Destination objects whose underlying value is proprietary and therefore undefined.<br />

The JMSRedelivered value may be changed during delivery. If a consumer uses a message<br />

selector where "JMSRedelivered = FALSE", and there was a failure delivering a message,<br />

the JMSRedelivered flag might be set to TRUE. JMSExpiration is not supported as an<br />

identifier because JMS providers may choose to implement this value differently. Some<br />

may store it with the message, while others calculate it as needed.<br />

D.2 Literals<br />

Literals are expression values that are hard-coded into the message selector. In the message<br />

selector shown here, 30, 100.00, and 'Smith' are all literals:<br />

Age < 30 AND Weight >= 100.00 AND LName = 'Smith'<br />

String literals are enclosed in single quotes. An apostrophe or single quote can be included<br />

in a String literal by using two single quotes (e.g., 'Smith''s').<br />

174

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!