<p>This example shows how messages with different priorities are delivered in different orders.</p>
<p>The Message Priority property carries the delivery preference of sent messages. It can be set by the message's
standard header field 'JMSPriority' as defined in JMS specification version 1.1. The value is of type
integer, ranging from 0 (the lowest) to 9 (the highest). When messages are being delivered, their priorities
will effect their order of delivery. Messages of higher priorities will likely be delivered before those
of lower priorities. Messages of equal priorities are delivered in the natural order of their arrival at
their destinations. Please consult the JMS 1.1 specification for full details.</p>
<p>In this example, three messages are sent to a queue with different priorities. The first message is sent
with default priority (4), the second is sent with a higher priority (5), and the third has the highest
priority (9). At the receiving end, we will show the order of receiving of the three messages. You will
see that the third message, though last sent, will 'jump' forward to be the first one received. The second
is also received ahead of the message first sent, but behind the third message. The first message, regardless
of its being sent first, arrives last.</p>
<h2>Example step-by-step</h2>
<p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>
<ol>
<li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
if (!rm.getText().equals(sentMessages[2-i].getText()))
{
System.err.println("Priority is broken!");
result = false;
}
}
</code>
</pre>
<li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>