Integrate ActiveMQ with JBoss




Screencast shows how to:

1. Deploy ActiveMQ
2. Run consumer/supplier samples
3. Integrate JBoss AS 6 and ActiveMQ
4. Enqueue TextMessage from EJB using ActiveMQ



Software:
JBoss 6.1.0
Apache Active MQ 5.4.3


And i will use centos 6.6.


I created user jboss and installed jdk 1.7.0_75


JBoss 6.1.0.Final Installation

# mkdir -p /opt/jboss/6.1.0/
# chown -R jboss /opt/jboss/6.1.0/
# su - jboss


$ cd /tmp/
$ wget http://download.jboss.org/jbossas/6.1/jboss-as-distribution-6.1.0.Final.zip


$ unzip jboss-as-distribution-6.1.0.Final.zip
$ cd jboss-6.1.0.Final/
$ mv * /opt/jboss/6.1.0/


$ vi ~/.bash_profile


#### JBoss 6.1.0 ##################

export JBOSS_HOME=/opt/jboss/6.1.0
export PATH=$PATH:$HOME/bin:$JBOSS_HOME/bin

#### JBoss 6.1.0 ##################


$ source ~/.bash_profile


Active MQ 5.4.3 Installation

# mkdir -p /opt/active-mq/5.4.3/
# chown -R jboss /opt/active-mq/5.4.3/
# su - jboss


$ cd /tmp/
$ wget http://archive.apache.org/dist/activemq/apache-activemq/5.4.3/apache-activemq-5.4.3-bin.zip


$ unzip apache-activemq-5.4.3-bin.zip
$ cd apache-activemq-5.4.3
$ mv * /opt/active-mq/5.4.3/


$ cd /opt/active-mq/5.4.3/bin/
$ java -jar run.jar start

http://192.168.56.3:8161/admin/

192.168.56.3 - my virtual mashine ip address.


First Example with Active MQ Server

Eclipse -> Project Explorer -> Right Click -> Import -> Import -> Git

Project source codes


To work with remote server, you should change url:

private String url = "failover://tcp://192.168.56.3:61616";

run ProducerTool.java as Java Application

Queue –> 10 Queues added

run ConsumerTool.java as Java Application

Queue –> 10 Queues received


Active MQ integrating with JBoss

$ cd /opt/active-mq/5.4.3/lib/optional


$ ls activemq-rar-5.4.3.rar
activemq-rar-5.4.3.rar


$ unzip activemq-rar-5.4.3.rar -d /opt/jboss/6.1.0/server/default/deploy/activemq-rar.rar


$ cd /opt/jboss/6.1.0/server/default/deploy/


$ vi activemq-jms-ds.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE connection-factories
    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<connection-factories>

    <tx-connection-factory>
        <jndi-name>activemq/QueueConnectionFactory</jndi-name>
        <xa-transaction/>
        <track-connection-by-tx/>
        <rar-name>activemq-rar.rar</rar-name>
        <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
        <ServerUrl>vm://localhost</ServerUrl>
        <!--
        <UserName>sa</UserName>
        <Password></Password>
        -->
        <min-pool-size>1</min-pool-size>
        <max-pool-size>200</max-pool-size>
        <blocking-timeout-millis>30000</blocking-timeout-millis>
        <idle-timeout-minutes>3</idle-timeout-minutes>
    </tx-connection-factory>

    <tx-connection-factory>
        <jndi-name>activemq/TopicConnectionFactory</jndi-name>
        <xa-transaction/>
        <track-connection-by-tx/>
        <rar-name>activemq-rar.rar</rar-name>
        <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
        <ServerUrl>vm://localhost</ServerUrl>
        <!--
        <UserName>sa</UserName>
        <Password></Password>
        -->
        <min-pool-size>1</min-pool-size>
        <max-pool-size>200</max-pool-size>
        <blocking-timeout-millis>30000</blocking-timeout-millis>
        <idle-timeout-minutes>3</idle-timeout-minutes>
    </tx-connection-factory>

    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">
        <attribute name="JNDIName">activemq/queue/outbound</attribute>
        <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-rar.rar'</depends>
        <attribute name="Type">javax.jms.Queue</attribute>
        <attribute name="Properties">PhysicalName=queue.outbound</attribute>
    </mbean>

    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">
        <attribute name="JNDIName">activemq/topic/inbound</attribute>
        <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-rar.rar'</depends>
        <attribute name="Type">javax.jms.Topic</attribute>
        <attribute name="Properties">PhysicalName=topic.inbound</attribute>
    </mbean>

</connection-factories>


Original article:
http://activemq.apache.org/integrating-apache-activemq-with-jboss.html

run jboss server

$ cd /tmp/
$ nohup run.sh -c default -b 0.0.0.0


+1 ssh session to console:

$ cd /tmp/
$ less nohup.out



I found in JBoss log:

***
10:03:51,828 INFO  [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQQueue' at 'activemq/queue/outbound'
10:03:51,871 INFO  [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQTopic' at 'activemq/topic/inbound'
10:03:52,138 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/QueueConnectionFactory' to JNDI name 'java:activemq/QueueConnectionFactory'
10:03:52,261 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/TopicConnectionFactory' to JNDI name 'java:activemq/TopicConnectionFactory'
***


Project from video:
https://www.youtube.com/watch?v=85Zw-Z_GDpQ


Result my source code:

(If project will not work, change java:/ on java: in the QueueConnectionFactory)


repo


I compiled this project with jdk 1.6 and copied project to deploy folder.


JBoss Active MQ Integration


Next Step. I want to repeat this lesson with wildfly 8.2.

I installed wildfly 8.2, and attached activemq as a module


standalone-full.xml

<subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">
    <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:/activemq/QueueConnectionFactory" enabled="true" use-java-context="true" pool-name="QueueConnectionFactory"/>
            </connection-definitions>
            <admin-objects>
                <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="activemq/queue/outbound" use-java-context="true" pool-name="test_queue">
                    <config-property name="PhysicalName">
                        queue.outbound
                    </config-property>
                </admin-object>
            </admin-objects>
        </resource-adapter>
    </resource-adapters>
</subsystem>


20:11:01,958 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA ConnectionFactory [java:/activemq/QueueConnectionFactory]
20:11:01,959 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-1) JBAS010401: Bound JCA AdminObject [java:/activemq/queue/outbound]

All Works.