O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
}<br />
Topic topic = (Topic)text<strong>Message</strong>.getJMSDestination( );<br />
System.out.println(topic.getTopicName( )+" : "+text);<br />
} catch (JMSException jmse){jmse.printStackTrace( );}<br />
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The JMSDestination header is set automatically by the JMS provider when the message is<br />
delivered. The Destination used in the JMSDestination is typically specified when the<br />
publisher is created, as shown here:<br />
Queue queue = (Queue)jndi.lookup(queueName);<br />
QueueSender queueSender = session.createSender(queue);<br />
<strong>Message</strong> message = session.create<strong>Message</strong>( );<br />
queueSender.send(message);<br />
...<br />
Topic topic = (Topic)jndi.lookup(topicName);<br />
TopicPublisher topicPublisher = session.createPublisher(topic);<br />
<strong>Message</strong> message = session.create<strong>Message</strong>( );<br />
topicPublisher.publish(message);<br />
An unspecified message producer - one created without a Destination - will require that a<br />
Destination be supplied with each send( ) operation:<br />
QueueSender queueSender = session.createSender(null);<br />
<strong>Message</strong> message = session.create<strong>Message</strong>( );<br />
Queue queue = (Queue)jndi.lookup(queueName);<br />
queueSender.send(queue, message);<br />
...<br />
TopicPublisher topicPublisher = session.createPublisher(null);<br />
<strong>Message</strong> message = session.create<strong>Message</strong>( );<br />
Topic topic = (Topic)jndi.lookup(topicName);<br />
topicPublisher.publish(topic, message);<br />
In this case, the JMSDestination header becomes the Destination used in the send( )<br />
operation.<br />
JMSDeliveryMode Purpose: Routing<br />
There are two types of delivery modes in JMS: persistent and nonpersistent. A persistent<br />
message should be delivered once-and-only-once, which means that a message is not lost<br />
if the JMS provider fails; it will be delivered after the server recovers. A nonpersistent<br />
message is delivered at-most-once, which means that it can be lost and never delivered if<br />
the JMS provider fails. In both persistent and nonpersistent delivery modes the message<br />
server should not send a message to the same consumer more than once, but it is possible;<br />
see the section on JMSRedelivered for more details.<br />
Persistent messages are intended to survive system failures of the JMS provider (the<br />
message server). Persistent messages are written to disk as soon as the message server<br />
receives them from the JMS client. After the message is persisted to disk the message<br />
server can then attempt to deliver the message to its intended consumer. As the messaging<br />
server delivers the message to the consumers it keeps track of which consumers<br />
successfully receive the message. If the JMS provider fails while delivering the message,<br />
the message server will pick up where it left off following a recovery. Persistent messages<br />
157