One of the great features of Jboss Fuse and the underlying Apache Camel is that it can be deployed virtually anywhere. However one of the runtime possibilities that comes out of the box with Jboss Fuse is Fuse Fabric, which uses fabric8 containers as a runtime.
In fabric8 the deployable unit is a fabric profile. In this post we will create a fabric profile containing a Jboss Fuse project. Then we will create and startup a fabric container and provision this container firstly with the Jboss Fuse runtime and finally with our fabric profile containing a camel route. We will use maven for most of the build and deployment steps.
Note this post will not go into detail how to setup your fabric8 environment and assumes you already have a running fabric with a running root container.
As mentioned above we are using the Fuse spring example which you get for free after creating a Fuse project using the spring archetype for Fuse. The only thing I changed in the Camel route of this example is the location of the directories used for reading and writing the files. I changed it so it no longer uses a directory in the project but just some location on my file system for quick testing.
Here is the example Camel route:
We are going to deploy the project containing this route as a fabric profile. This fabric profile can than be added to a fabric container which, in this case, acts as a karaf runtime for Fuse. We are going to use maven for all the build and deploy steps.
To deploy our project into a container we need to walk through the following steps:
- Update the pom.xml file
- do a Maven install
- deploy your project using maven
- create a fabric container
- add the fabric profile to the container
Update the pom.xml file
To deploy our Fuse project using maven we need to make some changes to our pom file. We need to change the following:
- Add info for creating the OSGi bundle
- Add Apache Felix plugin
- Add Fabric8 plugin and properties
Add info for creating the OSGi bundle
To use an OSGi bundle we need to change two things in our pom file.
- Change the packaging from jar to bundle
- add Apache Felix plugin
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.7</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>fabricdemo</Bundle-SymbolicName> <Private-Package>nl.rubix.fabricdemo.*</Private-Package> <Import-Package>*</Import-Package> </instructions> </configuration> </plugin>
Add Fabric8 plugin and properties
Next up is adding the fabric8 stuff to our pom file. This contains a the fabric8 plugin adding some fabric8 properties and removing the existing maven plugins.
Add Fabric8 maven plugin
<!-- fabric8 plugin for using deploying via mvn fabric:deploy --> <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> </plugin>
Add Fabric8 properties
there are a lot of fabric8 properties, for this simple demo we are going to use only one for setting the name of the fabric profile:
<fabric8.profile>fabricdemo</fabric8.profile>
Optionally you can add other fabric8 properties for adding specific features to your fabric profile or defining a parent profile for creating a profile hierarchy. For example:
<fabric8.features>camel camel-cxf</fabric8.features> <fabric8.parentProfiles>feature-camel</fabric8.parentProfiles>
Remove the existing maven plugin
finally we need to remove the existing maven plugins so no conflicts can arrise using the fabric plugin.
Remove the following 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>
Do a Maven install
execute the command ‘mvn install’
Note if you want to skip unit tests execute the command ‘mvn -Dmaven.test.skip=true install’
optional if you want to run your Camel route locally so you can do some manual testing execute the command: ‘mvn camel:run’
Deploy your project using Maven
Now we are ready to deploy our Fuse project as a fabric profile making it available in fabric8.
To do this simply execute the command: ‘mvn fabric8:deploy’
The first time you execute this command for a particular project it can take up some time when Maven is downloading all the nessecary jar files. After the deployment is successful the output should look something like this:
[INFO] Updating profile: fabricdemo with parent profile(s): [feature-camel] using OSGi resolver [INFO] About to invoke mbean io.fabric8:type=ProjectDeployer on jolokia URL: http://localhost:8181/jolokia with user: admin [INFO] Result: DeployResults{profileUrl='null', profileId='fabricdemo', versionId='1.0'} [INFO] Uploading file ReadMe.txt to invoke mbean io.fabric8:type=Fabric on jolokia URL: http://localhost:8181/jolokia with user: admin [INFO] No profile configuration file directory /home/jboss/workspace/fabricdemo/src/main/fabric8 is defined in this project; so not importing any other configuration files into the profile. [INFO] Performing profile refresh on mbean: io.fabric8:type=Fabric version: 1.0 profile: fabricdemo [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2:56.842s [INFO] Finished at: Sun Sep 14 13:30:51 CEST 2014 [INFO] Final Memory: 28M/120M [INFO] ------------------------------------------------------------------------ [jboss@localhost fabricdemo]$
Now we can switch to Hawtio for finalizing our deployment and starting our application.
Create a fabric container
We assume you have already created a fabric and your server is running.
In the karaf console the command ‘fabric:container-list’ should output something like this:
Now we can switch to hawtio to finish up the deployment. Go to localhost:8181 (or, when using a remote server to the server address) to start up the hawtio console.
The startup screen (after you log in) should look something like this:
now click the create button to create a new container which we will use to deploy our newly created fabric profile into.
Type a container name, in this example I am using fabric8 demo. Then enter ‘full’ into the search box and select jboss/fuse full. This will provision the container with the Fuse runtime (like Apache Camel, CXF and ActiveMQ). Now press ‘Create and Start Container’
After some time our new container will be started:
however we still need to provision this container with the fabric profile we created earlier.
Add the fabric profile to the container
After the new container is started click on the container -> now add the fabric profile we just deployed with maven. click Add -> expand ‘Uncategorized’ -> select your profile → click Add
Now fabric8 will provision the container with our fabric profile. After it is done provisioning and the container is running you should see something like this:
Note the little Camel after Services and the camel in the JMS Domains.
Now our Fuse project is correctly deployed and running in a fabric8 container. To open the container simply click the Open button and the Hawtio console of the container will open in a new browser tab.
When we go to the Camel tab we can expand the route we have just deployed to see how many messages the route has processed. After some test messages it seems our route is working!
The complete pom.xml file used for this project:
<?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>nl.rubix</groupId> <artifactId>fabricdemo</artifactId> <packaging>bundle</packaging> <version>1.0.0-SNAPSHOT</version> <name>A Camel Spring Route</name> <url>http://www.myorganization.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <fabric8.profile>fabricdemo</fabric8.profile> </properties> <repositories> <repository> <id>release.fusesource.org</id> <name>FuseSource Release Repository</name> <url>http://repo.fusesource.com/nexus/content/repositories/releases</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>ea.fusesource.org</id> <name>FuseSource Community Early Access Release Repository</name> <url>http://repo.fusesource.com/nexus/content/groups/ea</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>snapshot.fusesource.org</id> <name>FuseSource Snapshot Repository</name> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>release.fusesource.org</id> <name>FuseSource Release Repository</name> <url>http://repo.fusesource.com/nexus/content/repositories/releases</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> <pluginRepository> <id>ea.fusesource.org</id> <name>FuseSource Community Early Access Release Repository</name> <url>http://repo.fusesource.com/nexus/content/groups/ea</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> <pluginRepository> <id>snapshot.fusesource.org</id> <name>FuseSource Snapshot Repository</name> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>false</enabled> </releases> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>2.12.0.redhat-610379</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>2.12.0.redhat-610379</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>2.12.0.redhat-610379</version> <scope>test</scope> </dependency> </dependencies> <build> <defaultGoal>install</defaultGoal> <plugins> <!-- allows the route to be ran via 'mvn camel:run' --> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId> <version>2.12.0.redhat-610379</version> </plugin> <!-- apache felix plugin for creating OSGi bundle --> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.7</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>homeloan</Bundle-SymbolicName> <Private-Package>nl.rubix.fabricdemo.*</Private-Package> <Import-Package>*</Import-Package> </instructions> </configuration> </plugin> <!-- fabric8 plugin for using deploying via mvn fabric:deploy --> <plugin> <groupId>io.fabric8</groupId> <artifactId>fabric8-maven-plugin</artifactId> </plugin> </plugins> </build> </project>