Using Standalone ActiveMQ Broker with Wildfly

Wildfly is an open source J2EE container, which comes with an embedded HornetQ JMS broker enabled by default in it’s full configuration. The embedded HornetQ works great out of the box, but sometimes it can be handy to use an existing JMS broker, like ActiveMQ. ActiveMQ includes a JCA resource adaptor that can be used to integrate it with J2EE containers. Below we will see how to integrate standalone ActiveMQ 5.13.2 with Wildfly 9.0.2 server.

The first step is to download, tweak and deploy the ActiveMQ Resource Adaptor (RA) on Wildfly. ActiveMQ RA binaries are available on Apache’s site for download. So lets download and unpack the adaptor.

unzip -d activemq-rar activemq-rar-5.13.2.rar

Now, because we don’t need to run ActiveMQ embedded in Wildfly, we’ll comment out the necessary configuration. This can be done by editing the activemq-rar/META-INF/ra.xml, and removing the config-property with the following comment:

<!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->

After this we’ll pack the adaptor and deploy it on Wildfly.

cd activemq-rar # Directory where the rar file was unpacked in the previous step
zip activemq-rar-5.13.2.rar .
cp activemq-rar-5.13.2.rar $WILDFLY_HOME/standalone/deployments

We can now configure this Resource Adaptor on Wildfly in order to create and bind an ActiveMQ connection factory in JNDI. Below is a sample configuration that we need in Wildfly’s standalone.xml configuration file (or the server’s current domain configuration file depending on the setup). The resource adaptor configuration reference is available on Apache’s site

<subsystem xmlns="urn:jboss:domain:resource-adapters:3.0">
        <resource-adapter id="activemq">
            <config-property name="UseInboundSession">false</config-property>
            <config-property name="ServerUrl">tcp://localhost:61616</config-property>
                <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory">
                <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/jms/queue/test-queue" use-java-context="true" pool-name="test-queue">
                    <config-property name="PhysicalName">jms/queue/test-queue</config-property>

After this, in our applications deployed on Wildfly, we can simply lookup the ActiveMQConnectionFactory from JNDI (java:/ConnectionFactory) and start sending and receiving messages.

Leave a Reply