<p>The example application will invoke an EJB which is deployed within WildFly which will:</p>
<ol>
<li>start an XA transaction</li>
<li>send a JMS message</li>
<li>update an in-memory database</li>
<li>commit the transaction</li>
</ol>
<p>The example application will then receive the message sent by the EJB.</p>
<h2>WildFly configuration</h2>
<p>The example leverages the Arquillian framework to run a WildFly instance and deploy the MDB.</p>
<h2>Example step-by-step</h2>
<p><i>download WildFly 8.0.0.Final from <ahref="http://wildfly.org/downloads/">here</a> and install.</i></p>
<p><i>set the JBOSS_HOME property to point to the WildFly install directory</i></p>
<p><i>type <code>mvn verify</code> from the example directory to run</i></p>
<p>The example code is composed of two main classes:</p>
<ul>
<li><code>EJBClientExample</code></li> - the example application
<li><code>SendMessageBean</code></li> - a Stateless EJB with a remote interface
</ul>
<h3>Example Application</h3>
<p>Let's take a look at EJBClientExample first.</p>
<ol>
<li>First we need to get an initial context so we can look-up the EJB. This initial context will get it's properties from the jboss-ejb-client.properties.</li>
SendMessageService service = (SendMessageService) initialContext.lookup("ejb:/test//SendMessageBean!org.apache.activemq.javaee.example.server.SendMessageService");
<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>
<preclass="prettyprint">
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}
</pre>
</ol>
<h3>EJB Example</h3>
<p>Let's now take a look at the EJB example</p>
<ol>
<li>First, we create a new initial context</li>
<preclass="prettyprint">
ic = new InitialContext();
</pre>
<li>We look up the JMS <em>XA</em> Connection Factory (which is bound to <code>java:/JmsXA</code>)</li>
<li>And finally, <b>always</b> remember to close all your connections and resources (for both JMS and JDBC) after use, in a <code>finally</code> block.</li>