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.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
JMSPriority Purpose: Routing<br />
<strong>Message</strong>s may be assigned a priority by the message producer when they are delivered.<br />
The message servers may use message's priority to order delivery of messages to<br />
consumers; messages with a higher priority are delivered ahead of lower priority messages.<br />
The message's priority is contained in the JMSPriority header, which is set automatically<br />
by the JMS provider. The priority of messages can be declared by the JMS client using the<br />
setPriority( ) method on the producer. The following code shows how this method is<br />
used by both the p2p and pub/sub message models:<br />
// p2p setting the message priority to 9<br />
QueueSender queueSender = QueueSession.createSender(someQueue);<br />
queueSender.setPriority(9);<br />
//pub/sub setting the message priority to 9<br />
TopicPublisher topicPublisher = TopicSession.createPublisher(someTopic);<br />
topicPublisher.setPriority(9);<br />
Once a priority is established on a producer (QueueSender or TopicPublisher), that priority<br />
will be used for all messages delivered from that producer, unless it is explicitly<br />
overridden. The priority of a specific message can be overridden during the send operation.<br />
The following code shows how to override the priority of a message during the send<br />
operation. In both cases, the priority is set to 3:<br />
// p2p setting the priority on the send operation<br />
QueueSender queueSender = QueueSession.createSender(someQueue);<br />
queueSender.send(message,DeliveryMode.PERSISTENT, 3, 0);<br />
// pub/sub setting the priority on the send operation<br />
TopicPublisher topicPublisher = TopicSession.createPublisher(someTopic);<br />
topicPublisher.publish(message,DeliveryMode.PERSISTENT, 3, 0);<br />
There are two basic categories of message priorities: levels 0-4 are gradations of normal<br />
priority; levels 5-9 are gradations of expedited priority. <strong>Message</strong> servers are not required to<br />
enforce message ordering based on the JMSPriority header, but they should attempt to<br />
deliver expedited messages before normal messages.<br />
The JMSPriority header is set automatically when the message is delivered. It can be read<br />
by JMS clients using the <strong>Message</strong>.getJMSPriority( ) method, but it is mostly used by<br />
message servers when routing messages.<br />
163