23.07.2013 Views

O'Reilly - Java Message Service

O'Reilly - Java Message Service

O'Reilly - Java Message Service

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Appendix D.) Therefore, durable subscriptions must be identified by their own name;<br />

simply using the topic name and the client ID will not suffice.<br />

Figure 4.2. Managing active durable subscriptions<br />

The JMS specification is intentionally vague about how the JMS provider determines the<br />

uniqueness of a client ID. Various provider implementations are allowed to have their own<br />

internal rules for what constitutes a unique client. The setClientID( ) method on the<br />

connection object is provided in the API as a hint. The client ID is set in the constructor of<br />

our Retailer example:<br />

public Retailer( String broker, String username, String password){<br />

try {<br />

....<br />

connect = factory.createTopicConnection (username, password);<br />

connect.setClientID(username);<br />

....<br />

}<br />

....<br />

}<br />

4.4 Publishing the <strong>Message</strong> Persistently<br />

Both the Wholesaler and Retailer classes publish messages using the persistent delivery<br />

mode:<br />

publisher.publish(<br />

message,<br />

javax.jms.DeliveryMode.PERSISTENT,<br />

javax.jms.<strong>Message</strong>.DEFAULT_PRIORITY,<br />

1800000);<br />

Note the use of the overloaded publish( ) method, with parameters that specify delivery<br />

mode, priority, and message expiration. This method provides an alternative to using the<br />

<strong>Message</strong>.setJMSDeliveryMode( ) and TopicPublisher.setTimeToLive( ) operations, as<br />

discussed in Chapter 3. In JMS, the delivery mode (persistent, nonpersistent) is a Quality<br />

of <strong>Service</strong> (QoS) setting on the message itself. Marking the message as persistent ensures<br />

that the message will be saved to a reliable persistent store by the JMS provider before the<br />

63

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

Saved successfully!

Ooh no, something went wrong!