or a <code>Topic</code> by prefixing with <code>jms.topic.</code>.<br/>
In this example, we will use a <code>Queue</code> to hold the expired messages.</p>
<p>Since we want to consume messages from this expiryQueue, we also need to add a JNDI binding to perform a lookup.
This is configured in <ahref="server0/hornetq-jms.xml">hornetq-jms.xml</a></p>
<preclass="prettyprint">
<code><queue name="expiryQueue">
<entry name="/queue/expiryQueue"/>
</queue></code>
</pre>
</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>
<li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
<preclass="prettyprint">
<code>connection.start();</code>
</pre>
<li>We try to receive a message from the queue. Since there is none, the call will timeout after 5000ms and <code>messageReceived</code> will be <code>null</code>
<li>The expired message's destination is the expiry queue</li>
<preclass="prettyprint">
<code>System.out.println("Destination of the expired message: " + ((Queue)messageReceived.getJMSDestination()).getQueueName());</code>
</pre>
<li>The expired message has its own <em>expiration time</em> (its time to live in the <strong>expiry queue</strong>)</li>
<preclass="prettyprint">
<code>System.out.println("Expiration time of the expired message (relative to the expiry queue): " + messageReceived.getJMSExpiration());</code>
</pre>
<p>As we have not defined a time-to-live for the expiry queue, messages sent to the expiry queue will be kept forever (their JMS Expiration value is 0)</p>
<li>The <strong>origin destination</strong> is stored in the <code>_HORNETQ_ORIG_DESTINATION</code> property
<preclass="prettyprint">
<code>System.out.println("*Origin destination* of the expired message: " + messageReceived.getStringProperty("_HORNETQ_ORIG_DESTINATION"));</code>
</pre>
<li>The <strong>actual expiration time</strong> (when the message was expired from the queue) is stored in the <code>_HORNETQ_ACTUAL_EXPIRY</code> property
<preclass="prettyprint">
<code>System.out.println("*Actual expiration time* of the expired message: " + messageReceived.getLongProperty("_HORNETQ_ACTUAL_EXPIRY"));</code>
</pre>
</p>
<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>