How to Containerize Your Camel Route on Karaf Within OpenShift

DZone 's Guide to

How to Containerize Your Camel Route on Karaf Within OpenShift

We set up a simple camel route using an FIS based on a Karaf image, which we will use to containerize your camel route on Karaf within OpenShift.

· Integration Zone ·
Free Resource

The Red Hat JBoss Fuse solution offers a new approach to lightweight and modular ESBs and is perfectly suited to allow you to implement light integrations.

JBoss Fuse is based on the power of Apache Karaf. Apache Karaf lays in the easy deployment of your ActiveMQ Broker, your CXF web services, or your own Apache Camel routes.

Most of us are more familiar with that OSGI Environment and what they offer, like control of the classloader behavior and module isolation and APIs within a single app or JVM process.

For this post, we are going to set up a simple camel-route using an FIS (Fuse Integration Service) based on a Karaf image (jboss-fuse-6/fis-karaf-openshift), which we will use to containerize your camel route on Karaf within OpenShift!

To get started, you have a Maven Archetype catalog that includes some examples, but let's see my example available here.

This example shows a simple Apache Camel microservice that expose REST service and log a message in Karaf.

All the necessary dependencies of this Camel route are listed as features to our Karaf distribution on startup in the karaf-maven plugin:

 <!-- 2. create karaf assembly -->
      <!-- karaf-maven-plugin creates custom microservice distribution -->
          <!-- we are using karaf 2.4.x -->
          <!-- do not include build output directory -->
          <!-- no startupFeatures -->

We can overridden files using resources from src/main/resources/assembly/. The included sample log file etc/org.ops4j.pax.logging.cfg allows you to customize your logging. In my case, the log level is set to debug.

The Camel route is implemented using solely the XML DSL (there is no Java code). The source code is provided in the following XML file: src/main/resources/OSGI-INF/blueprint/camel-rest.xml :

<camelContext id="rest-example-context"

 <restConfiguration component="jetty" port="9191" />
<rest path="FIS">
<get uri="/{name}">
<to uri="direct:order" />
<route id="rest-route">
<from uri="direct:order" />
<simple>Welcome to: ${headers.name} on Fuse Integration Service in OpenShift</simple>
<log message=">>> ${body} : ${sys.runtime.id}" />

The endpoint of our Rest service is exposed on the port 9191. This port should be also declared and exposed in the Docker by setting the HTTP port in Docker Maven plugin:


The service is configured in pom.xml for fabric8 plugin to pick up:


In order to deploy this example to OpenShift, you can use one of the following application development workflows:

  • Fabric8 Maven workflow.
  • OpenShift source-to-image (S2I) workflow.

In the case of a local development environment, you can simply use fabric8 maven workflow by choosing -Pf8-local-deploy as a goal that creates Docker and JSON templates and then applies them to OpenShift.

mvn -Pf8-local-deploy

When the example runs in OpenShift, you can use the OpenShift client tool to inspect the status:

$ oc get pods
NAME                         READY     STATUS    RESTARTS   AGE
karaf-camel-rest-ose-k8fqw   1/1       Running   0          1h

Then find the name of the pod that runs this example and output the logs from the running pods with:

$ oc logs karaf-camel-rest-ose-k8fqw

You can test the application by running the restful endpoint:

curl http://karaf-camel-rest-ose.rhel-cdk.
Welcome to: aboucham on Fuse Integration Service in OpenShift

To access to the usual console hawt.io, this web console now is embedded by default in OpenShift Console, and you have to access to it by clicking on the button Open Java console":


In the application console, we see the route is active:


Thanks for reading, and I hope that you enjoyed this post!

integration ,containers ,camel ,openshift

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}