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.

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

When a JMS consumer declares a message selector for a particular<br />

destination, the selector is applied only to messages delivered to that<br />

consumer. Every JMS client can have a different selector specified<br />

for each of its consumers.<br />

What happens to messages that are not selected for delivery to the consumer by its<br />

message selector? This depends on the message model used. In the pub/sub model, the<br />

message is simply not delivered to that consumer, but it is delivered to other consumers.<br />

This is true of both nondurable and durable subscriptions. In the p2p model, the messages<br />

remain in the queue, so other consumers of the queue can see them, but they are not visible<br />

to the consumer that used the message selector.<br />

3.3.1 <strong>Message</strong> Selector Examples<br />

Here are three complex selectors used in hypothetical environments. Although you will<br />

have to use your imagination a little, the purpose of these examples is to convey the power<br />

of the message selectors. When a selector is declared, the identifier always refers to a<br />

property name or JMS header name in the message. For example, the selector "'username<br />

!= 'William'" assumes that there is a property in the message named username, which can<br />

be compared to the value 'William'.<br />

Managing claims in an HMO<br />

Due to some fraudulent claims, an automatic process is implemented that will audit<br />

all claims submitted by patients who are employees of the ACME manufacturing<br />

company with visits to chiropractors, psychologists, and dermatologists:<br />

String selector =<br />

"PhysicianType IN ('Chiropractor', 'Psychologist', 'Dermatologist') "<br />

+ "AND PatientGroupID LIKE 'ACME%'";<br />

TopicSubscriber subscriber =<br />

session.createSubscriber(topic, selector,false);<br />

Selecting recipients for a catalog mailing<br />

An online retailer wants to deliver a special catalog to any customer that orders more<br />

then $500.00 worth of merchandise where the average price per item ordered is<br />

greater than $75.00 and the customer resides in one of several states. The retailer<br />

creates a special application that subscribes to the order processing topic and<br />

processes catalog deliveries for only those customers that meet the defined criteria:<br />

String selector =<br />

"TotalCharge > 500.00 AND ((TotalCharge / ItemCount) >= 75.00) "<br />

+ "AND State IN ('MN', 'WI', 'MI', 'OH')";<br />

TopicSubscriber subscriber =<br />

session.createSubscriber(topic, selector,false);<br />

41

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

Saved successfully!

Ooh no, something went wrong!