This is a quickstart guide to fabric8 which is an open source integration platform for managing Java Containers. You will learn how it can be used to provision, automate and configure containers from a central location with a consistent UI.

Fabric is integrated into JBoss Fuse 6.1, therefore in order to use it, this is the list of tools you will need to install:

  • JBoss Fuse 6.1 or newer
  • Maven

Follow this tutorial Helloworld Fuse tutorial to learn how to get started with JBoss Fuse

Once installed, if you have not already done so, create one (or more users) by adding a line of the following form to the Fuse-install-dir/etc/users.properties file:

admin=admin,admin

Now start Fuse, executing from the shell:

$ fuse

Now we will create a fabric, using the password we have defined for the admin user. From the Karaf shell enter:

JBossFuse:karaf@root> fabric:create --zookeeper-password admin

Still from the Karaf shell, invoke the fabric:container-list command to see a list of all containers in your new fabric. You should see a listing something like this:

JBossFuse:karaf@root>  fabric:container-list
[id]                           [version] [connected] [profiles] [provision status]
root*                          1.0       true        fabric, fabric-ensemble-000
0-1, jboss-fuse-full, success

Create the Camel Blueprint project

Ok, now we will create a Maven project based on Camel archetype blue-printfabric tutorial integration jboss fuse

This Archetype will create an project based on a Camel Spring Route. First of all, we need to apply some changes to the pom.xml of this project in order to be able to deploy it to Fabric (see highlighted sections):

<?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>com.mycompany</groupId>
	<artifactId>camel-spring</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>fabric8demo</fabric8.profile>
		<fabric8.features>camel camel-cxf</fabric8.features>
		<fabric8.parentProfiles>feature-camel</fabric8.parentProfiles>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-core</artifactId>
			<version>2.14.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>2.14.0</version>
		</dependency>

		<!-- logging -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.7</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.7</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.14.0</version>
			<scope>test</scope>
		</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>2.14.0</version>
			</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>
						<Import-Package>*</Import-Package>
					</instructions>
				</configuration>
			</plugin>

			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>fabric8-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

Basically we need to specify that the project will generate a bundle, we need commenting some plugins to avoid conflicts with the build phase of the project and include the maven-bundle-plugin the fabric8-maven-plugin.

You might think of a bundle like a big collection of classes (e.g., project code, dependencies, and the class path).

Finally, let's choose some absolute paths for our Camel route. The Camel context is defined into the src/main/resources/META-INF/spring/camel-context.xml file:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       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">

	   <camelContext xmlns="http://camel.apache.org/schema/spring">
<route xmlns="http://camel.apache.org/schema/spring" id="route1">
        <from uri="file:D:\\camel\\in?noop=true"/>
        <choice>
            <when>
                <xpath>/person/city = 'London'</xpath>
                <log message="UK message"/>
                <to uri="file:D:\\camel\\out\\uk"/>
            </when>
            <otherwise>
                <log message="Other message"/>
                <to uri="file:D:\\camel\\out\\others"/>
            </otherwise>
        </choice>
    </route>
</camelContext>

</beans>

Done with the project it's now time to Package and deploy the project on Fabric.

Packaging the Project and deploying it on Fabric

In order to be able to use the fabric8-maven-plugin you need to include the fabric's repository user and password into Maven's settings.xml file:

<servers>
  <server>
     <id>fabric8.upload.repo</id>
     <username>admin</username>
     <password>admin</password>
  </server>
</servers>  

Next, execute the following Maven goals to package the project:

mvn clean install

Finally, deploy the project on Fabric with:

mvn fabric:deploy

Your Project should be deployed into Fabric, launch the hawtio Web console at http://localhost:8181 and enter the admin/admin credentials.

Configuring a Child Container on Fabric

Select the Fabric perspective and click on the Runtime upper Tab. The list of available containers should appear:

fabric 8 tutorial fuse example

Click on the +Create button to create a child container where we will deploy our project as a Profile.

fabric 8 tutorial fuse example

In the "Create New Container" window select the fabric8demo profile and the jboss-fuse-full profile. In the right side of the screen enter a name for the Container and the admin/admin credentials.

fabric 8 tutorial fuse example

Now the admin Container should be visible and running. Clicking on the child container (admin) will take you to the following screen:

fabric 8 tutorial fuse example fabric8

Check the fabric8demo profile and click on the Open button. You will be taked into the Container's perspective which, being based on Camel, contains a Camel upper tab. Click on it to see the available Camel Contexts:

fabric tutorial fuse jboss

From there you can have a look at the Source code of your Camel route, Debug your Route or see from the Diagram window the list of messages which have been routed by our File component.

fabric 8 tutorial fuse example fabric8

If you have placed the message1.xml and message2.xml files which are part of the Maven project in the correct folders, and the Route has started, you will see that messages are moved from the "In" folder to the "Out" folder based on the content of the file.

Check out the Logs tab to see that Camel route is consuming messages.

2015-04-04 23:09:56 INFOorg.apache.camel.osgi.OsgiSpringCamelContext Route: route1 started and consuming from: Endpoint[file:D:\\camel\\in?noop=true]
2015-04-04 23:09:56 INFOorg.apache.camel.osgi.OsgiSpringCamelContext Total 1 routes, of which 1 is started.

 

0
0
0
s2smodern