This tutorial describes how you can integrate Apache Camel in your WildFly Application Server configuration. At the end of this tuorial you will be able to turn your WildFly application server into a mini service bus!
First of all, you need to grab the WildFly-camel bundle which is available at https://github.com/wildfly-extras/wildfly-camel
Simply unzip the tar.gz file into your application server home directory
tar xvfz wildfly-camel-patch-2.2.0.tar.gz
The above archive will extract modules and two configuration files named standalone-camel.xml and domain-camel.xml
Within the configuration file, you will find the the WildFly's Camel subsystem which allows you to add Camel Routes as part of the WildFly configuration. Routes can also be deployed as part of JavaEE applications and JavaEE components can access the Camel Core API and various Camel Component APIs.
Let's see a simple example of a route which moves files from one folder to another:
<subsystem xmlns="urn:jboss:domain:camel:1.0"> <camelContext id="system-context-1"> <![CDATA[ <route> <from uri="file:/home/wildfly/in?noop=true"/> <to uri="file:/home/wildfly/out"/> </route> ]]> </camelContext> </subsystem>
In order to test the above route, simply place a file into the "from" route and expect to find them copied into the "to" part of the route. If the files path are correct, the file transfer will work as you start the application server with a camel configuration.
./standalone.sh -c standalone-camel.xml
The Camel bundle also includes hawtio console which will let you dig into the Camel subsystem.
A login/password will be requested to access:
Where are user/names and password stored ? Obviously in a security domain:
<security-domain name="hawtio-domain" cache-type="default"> <authentication> <login-module code="RealmDirect" flag="required"> <module-option name="realm" value="ManagementRealm"/> </login-module> </authentication> </security-domain>
The hawtio-domain security domain relies on the RealmDirect and ManagementRealm, therefore you can use WildFly administration user and password to access the hawtio console as well
As you can see, by selecting the Camel tab, you can get right into the Attributes of your route which was executed once:
The route diagram shows the nodes which have been executed (you can even debug the execution of the route!):
This was just a quick introduction to the Camel integration with WildFly. In the part two of this tutorial we will show how to use Camel routes in Java EE applications using the Camel subsystem. A big thanks to Thomas Diesler for setting up this awesome project on GitHub!