Java Reference
In-Depth Information
send to the temporary destination. If you close the connection to which a temporary des-
tination belongs, the destination is closed and its contents are lost.
You can use temporary destinations to implement a simple request/reply mechanism. If
you create a temporary destination and specify it as the value of the JMSReplyTo mes-
sage header field when you send a message, then the consumer of the message can use the
value of the JMSReplyTo field as the destination to which it sends a reply. The consumer
can also reference the original request by setting the JMSCorrelationID header field
of the reply message to the value of the JMSMessageID header field of the request. For
example, an onMessage method can create a session so that it can send a reply to the
message it receives. It can use code such as the following:
Click here to view code image
producer = session.createProducer(msg.getJMSReplyTo());
replyMsg = session.createTextMessage("Consumer " +
"processed message: " + msg.getText());
replyMsg.setJMSCorrelationID(msg.getJMSMessageID());
producer.send(replyMsg);
For more examples, see Chapter 21 , Java Message Service Examples .
Using Advanced Reliability Mechanisms
The more advanced mechanisms for achieving reliable message delivery are the follow-
ing:
Creating durable subscriptions : You can create durable topic subscriptions,
which receive messages published while the subscriber is not active. Durable sub-
scriptions offer the reliability of queues to the publish/subscribe message domain.
Using local transactions : You can use local transactions, which allow you to
group a series of sends and receives into an atomic unit of work. Transactions are
rolled back if they fail at any time.
Creating Durable Subscriptions
To ensure that a pub/sub application receives all published messages, use PERSISTENT
delivery mode for the publishers and durable subscriptions for the subscribers.
The Session.createConsumer method creates a nondurable subscriber if a topic is
specified as the destination. A nondurable subscriber can receive only messages that are
published while it is active.
Search WWH ::




Custom Search