How to containerize your camel route on Karaf within OpenShift

Facebooktwittergoogle_plusredditpinterestlinkedinmail

The Red Hat JBoss Fuse solution offers a new approach of ESB lightweight and modular – 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 webservices, 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 isolatation and APIs within a single app/JVM process.

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

To get started, you have some Maven Archetype catalog includes some examples, but let’s see my example available here: [karaf-camel-rest-ose]:
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 karaf-maven plugin:

We can overridden files using resources  from src/main/resources/assembly/. The included sample log file etc/org.ops4j.pax.logging.cfg allow 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:

The endpoint of our Rest service is exposed on the port 9191. This port should be also declared & exposed in the docker by setting the http port in docker maven plugin:

and 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 case of local development environment, you can simply use fabric8 maven workflow by choosing -Pf8-local-deploy as a goal which creates docker and JSON templates and then apply 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.10.1.2.2.xip.io/FIS/aboucham
Welcome to: aboucham on Fuse Integration Service in OpenShift

To access to the usual console hawtio, 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”:

karaf_hawtio_ose

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

karaf_ose

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

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Abdellatif Bouchama

Abdellatif's main area of expertise lies within the fields of SOA, ESB, BigData and IoT.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>