External ActiveMQ with Wildfly 9.0.1

Target of this post is to configure a vanilla Wildfly 9.0.1 to use an external vanilla ActiveMQ 5.12.0. These are the latest releases on 2015-09-18. I got it running with following steps:

  1. Download Wildfly 9.0.1 if you don’t have it already: http://download.jboss.org/wildfly/9.0.1.Final/wildfly-9.0.1.Final.zip
  2. Download ActiveMQ 5.12.0 if you don’t have it already: http://www.apache.org/dyn/closer.cgi?path=/activemq/5.12.0/apache-activemq-5.12.0-bin.zip
  3. Download ActiveMQ Resource Adapter if you don’t have it already: https://repository.apache.org/content/repositories/releases/org/apache/activemq/activemq-rar/5.9.1/activemq-rar-5.9.1.rar
  4. Extract all the downloaded files. You can place Wildfly and ActiveMQ wherever you want. The resource adapter should go to $WILDFLY/modules/org/apache/activemq/main. All files in apache-activemq-5.12.0-bin.zip should go to this folder.
  5. Edit $WILDFLY/modules/org/apache/activemq/main/META-INF/ra.xml and remove the part marked with <!– NOTE disable the following property if you do not wish to deploy an embedded broker –>
  6. Add the file $WILDFLY/modules/org/apache/activemq/main/module.xml with this content
    <module xmlns="urn:jboss:module:1.1" name="org.apache.activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <resources>
        <resource-root path="."/>
        <resource-root path="activemq-broker-5.9.1.jar"/>
        <resource-root path="activemq-client-5.9.1.jar"/>
        <resource-root path="activemq-jms-pool-5.9.1.jar"/>
        <resource-root path="activemq-kahadb-store-5.9.1.jar"/>
        <resource-root path="activemq-openwire-legacy-5.9.1.jar"/>
        <resource-root path="activemq-pool-5.9.1.jar"/>
        <resource-root path="activemq-protobuf-1.1.jar"/>
        <resource-root path="activemq-ra-5.9.1.jar"/>
        <resource-root path="activemq-spring-5.9.1.jar"/>
        <resource-root path="aopalliance-1.0.jar"/>
        <resource-root path="commons-pool-1.6.jar"/>
        <resource-root path="commons-logging-1.1.3.jar"/>
        <resource-root path="hawtbuf-1.9.jar"/>
        <resource-root path="spring-aop-3.2.5.RELEASE.jar"/>
        <resource-root path="spring-beans-3.2.5.RELEASE.jar"/>
        <resource-root path="spring-context-3.2.5.RELEASE.jar"/>
        <resource-root path="spring-core-3.2.5.RELEASE.jar"/>
        <resource-root path="spring-expression-3.2.5.RELEASE.jar"/>
        <resource-root path="xbean-spring-3.15.jar"/>
      </resources>
      <exports>
        <exclude path="org/springframework/**"/>
        <exclude path="org/apache/xbean/**"/>
        <exclude path="org/apache/commons/**"/>
        <exclude path="org/aopalliance/**"/>
        <exclude path="org/fusesource/**"/>
      </exports>
      <dependencies>
        <module name="javax.api"/>
        <module name="org.slf4j"/>
        <module name="javax.resource.api"/>
        <module name="javax.jms.api"/>
        <module name="javax.management.j2ee.api"/>
      </dependencies>
    </module>
  7. Edit $WILDFLY/standalone/configuration/standalone.xml and add the following parts:
    • Under urn:jboss:domain:ejb3:3.0 add
      <mdb>
        <resource-adapter-ref resource-adapter-name="activemq-rar.rar"/>
        <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
      </mdb>
    • Under urn:jboss:domain:resource-adapters:3.0 add the resource adapter
      <resource-adapters>
          <resource-adapter id="activemq-rar.rar">
              <module slot="main" id="org.apache.activemq"/>
              <transaction-support>NoTransaction</transaction-support>
              <config-property name="ServerUrl">tcp://localhost:61616</config-property>
              <connection-definitions>
                  <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" use-java-context="true" pool-name="ConnectionFactory"/>
              </connection-definitions>
              <admin-objects>
                  <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="queue/test-queue" use-java-context="true" pool-name="test_queue">
                      <config-property name="PhysicalName">testQueue</config-property>
                  </admin-object>
              </admin-objects>
          </resource-adapter>
      </resource-adapters>
  8. In your project you will need to activate javax.jms.api in your jboss-deployment-structure.xml file (placed in WEB-INF folder):
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
        <deployment>
            <dependencies>
                <module name="javax.jms.api" export="true"/>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    
  9. Now you should be able to write your MDB like this
    import javax.ejb.ActivationConfigProperty;
    import javax.ejb.MessageDriven;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    
    @MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test-queue"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    })
    public class TestMDB implements MessageListener {
        @Override
        public void onMessage(Message msg) {
            // do something
        }
    }
  10. You will find the ActiveMQ management gui under http://localhost:8161/admin/. The default credentials are admin/admin.

Leave a Comment