Hi,

As we all know that the HornetQ codebase was donated to the Apache ActiveMQ project, and the HornetQ community joined to build a next-generation messaging broker. ActiveMQ Artemis includes many new features, and also retains protocol compatibility with the HornetQ broker. WildFly 10 includes this new exciting project as its JMS broker, and due to the protocol compatility, it fully replaces the HornetQ project. So as part of this simple demo we will see how we can connect to the ActiveMQ broker present inside the WildFLy10 via Standalone Apache Camel Route.

Find more about “Apache ActiveMQ Artemis” in http://hornetq.blogspot.in/2015/06/hornetq-apache-donation-and-apache.html
AND
http://activemq.apache.org/artemis/

Lets start WildFly 10 “standalone-full.xml” profile which has the “messaging-activemq” subsystem.

WildFLy 10 side configuration

Step-1). Now create a simple JMS Queue “TestQ” by running the following CLI command:

$ cd /PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/bin

$ ./jboss-cli.sh -c 
[standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=TestQ/:add(entries=["java:jboss/exported/TestQ"])
{"outcome" => "success"}

Following is the XML version of the same configuration which we just did via JBoss CLI:

        <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
            <server name="default">
                <security-setting name="#">
                    <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>
                </security-setting>
                <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>
                <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>
                <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">
                    <param name="batch-delay" value="50"/>
                </http-connector>
                <in-vm-connector name="in-vm" server-id="0"/>
                <http-acceptor name="http-acceptor" http-listener="default"/>
                <http-acceptor name="http-acceptor-throughput" http-listener="default">
                    <param name="batch-delay" value="50"/>
                    <param name="direct-deliver" value="false"/>
                </http-acceptor>
                <in-vm-acceptor name="in-vm" server-id="0"/>
                <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
                <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
                
                <!-- NOTICE BELOW -->
                <jms-queue name="TestQ" entries="java:jboss/exported/TestQ"/>
                
                <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
            </server>
        </subsystem>

==============

Step-2). Now next step is to add a user “jmsuser” with password “jmsuser@1” as part of “guest” role in the “ApplicationRealm” using the “$WildFly_Home/bin/add-user.sh” script

./add-user.sh 

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties) 
 b) Application User (application-users.properties)
(a): b

Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : jmsuser
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
 - The password should be different from the username
 - The password should not be one of the following restricted values {root, admin, administrator}
 - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password : 
Re-enter Password : 
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: guest
About to add user 'jmsuser' for realm 'ApplicationRealm'
Is this correct yes/no? yes
Added user 'jmsuser' to file '/PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/standalone/configuration/application-users.properties'
Added user 'jmsuser' to file '/PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/domain/configuration/application-users.properties'
Added user 'jmsuser' with groups guest to file '/PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/standalone/configuration/application-roles.properties'
Added user 'jmsuser' with groups guest to file '/PATH/TO/wildfly-10.0.0.CR3-SNAPSHOT/domain/configuration/application-roles.properties'
Is this new user going to be used for one AS process to connect to another AS process? 
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? no

Apache Camel Route Setup

Step-3). Now we will create a very simple Apache Camel based route which will send some messages (XML files) present in the local file system to the ActiveMQ “TestQ”.

So create the following directory structure in your file system:

$ mkdir -p Camel_With_ActiveMQ_On_WildFly10/src/data
$ mkdir -p Camel_With_ActiveMQ_On_WildFly10/src/main/resources/META-INF/spring

Step-4). We will use the following kind of “Camel_With_ActiveMQ_On_WildFly10/pom.xml” file to define the necessary repositories and the camel version along with the necessary plugins.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>middleware.magic</groupId>
	<artifactId>ApacheCamel_With_ActiveMQ_WilfFly</artifactId>
	<packaging>jar</packaging>
	<version>1.0</version>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<camel.version>2.15.3</camel.version>
		<wildfly.jms.client.bom>10.0.0.CR2</wildfly.jms.client.bom>
	</properties>

   <repositories>
        <repository>
            <id>jboss-enterprise-techpreview-group</id>
            <name>JBoss Enterprise Technology Preview  Maven Repository Group</name>
            <url>http://maven.repository.redhat.com/techpreview/all/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

	<dependencies>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
			<version>${camel.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jms</artifactId>
			<version>${camel.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>${camel.version}</version>
		</dependency>
		
		<!-- logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
		</dependency>


		<!-- testing -->
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-test-spring</artifactId>
			<version>${camel.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.wildfly</groupId>
			<artifactId>wildfly-jms-client-bom</artifactId>
			<version>${wildfly.jms.client.bom}</version>
			<type>pom</type>
		</dependency>
	</dependencies>

	<build>
		<defaultGoal>install</defaultGoal>

		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>

			<!-- allows the route to be ran via 'mvn camel:run' -->
			<plugin>
				<groupId>org.apache.camel</groupId>
				<artifactId>camel-maven-plugin</artifactId>
				<version>${camel.version}</version>
			</plugin>
		</plugins>
	</build>

</project>

Step-5). Now we will define the Camel Context inside the “Camel_With_ActiveMQ_On_WildFly10/src/main/resources/META-INF/spring/camel-context.xml” file. In this file we are referring to the “jmsQueueConnectionFactory” connection Factory and the “TestQ” which is present inside the Default Broker of WildFLy10:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <!-- Configuring Spring Jndi Template -->	
	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
		<property name="environment">
			<props>
				<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>
				<prop key="java.naming.provider.url">http-remoting://localhost:8080</prop>
			</props>
		</property>
	</bean>
	
    <!-- Getting ConnectionFactory using Spring Jndi Template -->	
	<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate">
			<ref bean="jndiTemplate" />
		</property>
		<property name="jndiName">
			<value>jms/RemoteConnectionFactory</value>
		</property>
	</bean>

    <!-- Spring based Security Part, Those are the users created in ApplicationRealm of WildFLy -->
	<bean id="authenticatedConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
		<property name="targetConnectionFactory" ref="jmsQueueConnectionFactory" />
		<property name="username" value="jmsuser" />
		<property name="password" value="jmsuser@1" />
	</bean>


	<bean name="jms" class="org.apache.camel.component.jms.JmsComponent">
		<property name="connectionFactory" ref="authenticatedConnectionFactory" />
	</bean>

	<camelContext xmlns="http://camel.apache.org/schema/spring">
		<route>
			<from uri="file:src/data?noop=true" />  <!-- Any file placed in this dir will be send to TestQ -->
			<to uri="jms:TestQ" />
		</route>
	</camelContext>
</beans>

Step-6). Lets put some XML files like “Camel_With_ActiveMQ_On_WildFly10/src/data/message.xml” which will be sent to the ActiveMQ broker using the Camel Route. As our Apache Camel Route is using the “?noop=true” so it will keep scanning the “src/data” directory for any new file processing. So as soon as you put any file in this directory it will be processed.

<?xml version="1.0" encoding="UTF-8"?>
<company>
   <name>MiddlewareMagic</name>
   <country>India</country>
   <city>Bangalore</city>
</company>

Step-7). Open a terminal and build the above mentioned Maven project. and then run the camel context as following:

export M2_HOME=/PATH/TO/apache_maven_3.2.3

export PATH=$JAVA_HOME/bin:/PATH/TO/apache_maven_3.2.3/bin:$SOAPUI_HOME/bin:$PATH:

cd Camel_With_ActiveMQ_On_WildFly10

$ mvn clean install

$ mvn camel:run
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building ApacheCamel_With_ActiveMQ_WilfFly 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> camel-maven-plugin:2.15.3:run (default-cli) > test-compile @ ApacheCamel_With_ActiveMQ_WilfFly >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ApacheCamel_With_ActiveMQ_WilfFly ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ ApacheCamel_With_ActiveMQ_WilfFly ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ApacheCamel_With_ActiveMQ_WilfFly ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /PATH/TO/Camel_With_ActiveMQ_On_WildFly10/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ ApacheCamel_With_ActiveMQ_WilfFly ---
[INFO] No sources to compile
[INFO] 
[INFO] <<< camel-maven-plugin:2.15.3:run (default-cli) < test-compile @ ApacheCamel_With_ActiveMQ_WilfFly <<<
[INFO] 
[INFO] --- camel-maven-plugin:2.15.3:run (default-cli) @ ApacheCamel_With_ActiveMQ_WilfFly ---
[INFO] Using org.apache.camel.spring.Main to initiate a CamelContext
[INFO] Starting Camel ...
[pache.camel.spring.Main.main()] MainSupport                    INFO  Apache Camel 2.15.3 starting
[pache.camel.spring.Main.main()] xnio                           INFO  XNIO version 3.3.2.Final
[pache.camel.spring.Main.main()] nio                            INFO  XNIO NIO Implementation Version 3.3.2.Final
[pache.camel.spring.Main.main()] remoting                       INFO  JBoss Remoting version 4.0.14.Final
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.3 (CamelContext: camel-1) is starting
[pache.camel.spring.Main.main()] ManagedManagementStrategy      INFO  JMX is enabled
[pache.camel.spring.Main.main()] DefaultTypeConverter           INFO  Loaded 183 type converters
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[pache.camel.spring.Main.main()] FileEndpoint                   INFO  Endpoint is configured with noop=true so forcing endpoint to be idempotent as well
[pache.camel.spring.Main.main()] FileEndpoint                   INFO  Using default memory based idempotent repository with cache max size: 1000
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route: route1 started and consuming from: Endpoint[file://src/data?noop=true]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Total 1 routes, of which 1 is started.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache Camel 2.15.3 (CamelContext: camel-1) started in 0.259 seconds

The “mvn camel:run” command will run the camel route and until the route is running any file which is placed inside the “Camel_With_ActiveMQ_On_WildFly10/src/data” directory will be processed by camel route (means will be send to the ActiveMQ Broker)

How to validate on WildFLy Side?

Try running the following “jboss-cli” command on the WildFly to list all the messages sent to the TestQ
List messages using CLI script:

[standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=TestQ:list-messages
{
    "outcome" => "success",
    "result" => [
        {
            "CamelFileLastModified" => 1393559256000L,
            "CamelFileParent" => "src/data",
            "JMSMessageID" => "ID:32212ff0-6b8b-11e5-8511-e3d2c5e4416f",
            "address" => "jms.queue.TestQ",
            "CamelFilePath" => "src/data/message1.xml",
            "JMSExpiration" => 0,
            "CamelFileLength" => 156,
            "JMSTimestamp" => 1444068129033L,
            "messageID" => 21,
            "JMSDeliveryMode" => "PERSISTENT",
            "CamelFileAbsolute" => false,
            "CamelFileName" => "message1.xml",
            "JMSPriority" => 4,
            "__AMQ_CID" => "32182f3d-6b8b-11e5-8511-e3d2c5e4416f",
            "CamelFileNameConsumed" => "message1.xml",
            "breadcrumbId" => "ID-BANL13bca644a-2-local-57971-1444068127436-0-1",
            "CamelFileRelativePath" => "message1.xml",
            "CamelFileAbsolutePath" => "/Camel_With_HornetQ/camelHornetq/src/data/message1.xml",
            "CamelFileNameOnly" => "message1.xml"
        },

SourceCode: Please find the source code of this project in MiddlewareMagic github repo:

https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/WildFly/JMS/Camel_With_ActiveMQ_On_WildFly10

Thanks
Jay SenSharma