<p>This example shows you how to use a TemporaryQueue with ActiveMQ. First a temporary queue is created to send and receive a message and then deleted.
Then another temporary queue is created and used after its connection is closed to illustrate its scope.</p>
<p>A TemporaryQueue is a JMS queue that exists only within the lifetime of its connection. It is often used in request-reply
type messaging where the reply is sent through a temporary destination. The temporary queue is often created as
a server resource, so after using, the user should call delete() method to release the resources.
Please consult the JMS 1.1 specification for full details.</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 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>
<preclass="prettyprint">
<code>initialContext = getContext();</code>
</pre>
<li>We look-up JMS connection factory from JNDI</li>
throw new Exception("Temporary queue cannot be accessed outside its lifecycle!");
}
catch (InvalidDestinationException e)
{
System.out.println("Exception got when trying to access a temp queue outside its scope: " + e);
}
</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>