and participate in XA transactions. It provides the javax.transaction.xa.XAResource interface for that
purpose. Users can get a XAConnectionFactory to create XAConnections and XASessions.</p>
<p>In this example we simulate a transaction manager to control the transactions. First we create an XASession
and enlist it in a transaction through its XAResource. We then send two words, 'hello' and 'world', with
the session, let the transaction roll back. The messages are discarded and never be received. Next we start
a new transaction with the same XAResource, but this time we commit the transaction. Both messages are received.</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 check that no messages should be received at this moment</li>
<preclass="prettyprint">
<code>checkNoMessageReceived();</code>
</pre>
<li>We commit!</li>
<preclass="prettyprint">
<code>xaRes.commit(xid2, false);</code>
</pre>
<li>We check that all messages are received.</li>
<preclass="prettyprint">
<code>checkAllMessageReceived();</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>