Cloud Native Camel Riding With JBoss Fuse and OpenShift
Red Hat debuted a neat microservices integration toolkit, perfect for running microservices in Kubernetes or Docker environments. Check out this guide to using JBoss Fuse, OpenShift, and Camel Boot!
Join the DZone community and get the full member experience.Join For Free
red hat recently released a microservices integration toolkit for running our microservices in a docker and kubernetes environment on openshift v3 . to help people understand this a little bit better, i’ve migrated the rider auto aookucatuib , which has been around for a while for demoing apache camel and jboss fuse, into a set of microservices that you can run on openshift/kubernetes via docker containers. this blog details some background on that and points to specific examples of “how-to” for a mostly non-trivial app. i’ll also do a set of videos demonstrating this so follow this blog ( http://blog.christianposta.com ) for updates or follow me on twitter @christianposta .
what is fuse integration services (fis) for openshift?
fis is a set of developer tools and docker images from the fabric8.io upstream community for packaging and deploying our applications that fit a model following a microservices architecture and opinionated best practices around application deployment, versioning, and lifecycle management. fis is a red hat-supported option for fuse on openshift.
the two main ways of deploying fuse integration services is via the karaf, osgi-based approach that fuse has traditionally used, as well as a simpler, flat-class loader option that boots camel from a plain old java main. both options are packaged and shipped in docker containers. both are good options depending on what you’re doing, so let’s take a look.
camel boot is a jvm bootstrap option that allows us to package our application using the same classpath that our maven project uses and boot our apache camel integrations using a plain old java main. this approach has a number of advantages that simplify building, assembling, distributing, and running our microservices. foremost, we don’t have to guess what our application behavior is based on hierarchies or graphs of complicated classloaders and whether we’ve included the correct metadata and dependencies so that classes may or may not resolve/collide/override/dynamically load/etc. we can simplify the model by just using a single, flat classloader to make it easier to reason about apps not only in dev but throughout the application lifecycle (eg, in ist, uat, pm, prod, etc, etc).
since this option is not meant to be deployed in any app-server (java ee app server, servlet container, osgi container, etc), we will rely on our app to provide “just enough” functionality that you’d otherwise expect in an app-server – stuff like http, jms, persistence, etc. so you can embed a jetty or undertow server inside our app to get http services for rest or soap endpoints and can embed jms clients like spring-jms and activemq libs to get messaging clients. this also makes it easier to unit test our app since all of those dependencies are included as part of the app and can be started, stopped, redeployed, etc independent of any app server.
i would suggest this camel boot option for most use cases where you’ve decomposed and modularized your applications and need to run, tune, scale, and reason about them individually. however, there are cases where co-locating services together are necessary and so long as the application classpath isn’t getting too complicated (ie conflicting dependencies), camel boot should be a good option. if your microservice is getting complicated because of cohesive, co-located services, consider the next option with apache karaf that allows you to finely control the classloader behavior and isolate modules and apis within a single app/jvm process.
“immutable” apache karaf
fuse integration services also offers an option for deploying to apache karaf based jvms, although the model is slightly different because we follow the docker model of “immutable” deployments. it can get quite difficult to reason about the state of a jvm after hot-deploying/re-deploying applications into/out of a running jvm. in fact, you can experience nasty, difficult to identify jvm leaks as a result of this “dynamic” mutability of the jvm at runtime (especially a bad idea in production). the model encouraged by fis is one of “shoot the old one and replace it” with a new version (and rely on the cluster manager to orchestrate this for you via rolling upgrades or blue-green deployments , etc).
what does this mean for apache karaf for fis? dynamic loading and unloading of bundles or altering configuration values at runtime to mutate application state is discouraged. instead, we encourage predictable startup ordering, understood configuration values, and pre-baked applications into the jvm. if things need to change, then you go through the application delivery pipeline to change/build/test/deploy a new version (via your ci/cd process ideally) just like you would for the above camel-boot option as well. so for karaf for fis, your app, and all its dependencies get packaged, installed, resolved, and built at build-time into a karaf assembly which is a custom distribution of karaf with your app baked into it. no more guessing about osgi metadata and class resolution at deploy time; it’s all pre-calculated and fails-fast at build time if things don’t resolve. you can be much more confident in your osgi app if things build successfully.
although the camel boot option is recommended for most use cases, for existing jboss fuse deployments outside of openshift/kubernetes/docker this karaf-based option may be your best option for migrating existing fuse workloads to this model (and take advantage of ci/cd, service discovery, cluster management, etc – already built into openshift). also, if you’re co-locating many services that end up polluting a flat-classpath the immutable karaf option is great for providing more granular classpath isolation and api/modularity modeling.
deploying to kubernetes/openshift
to deploy to openshift, we need to do the following:
- package our jvm (either camel-boot or immutable karaf)
- build our docker containers
- generate and apply our openshift/kubernetes config
packaging camel boot apps
to package our camel boot apps, all we need to do is include a maven
plugin that handles all of it for us.
in the above configuration for the
we can see that we just specify a plain old java main which will boot camel into the dependency injection context or your choice (spring, cdi, etc) and discover all of your spring/cdi resources as well as discover and start your camel routes. the different types of main.java files you can use are:
org.apache.camel.spring.main- discover your spring context files (default location meta-inf/spring/*.xml
org.apache.camel.cdi.main- loads the cdi container and the camel route beans
org.apache.camel.main.main- no dependency injection container; default simpleregistry implementation
org.apache.camel.spring.javaconfig.main- spring config using java config
org.apache.camel.guice.main- guice dependency injection container
it is probably worth adding the
as well so you can experiment and try out the bootstrapping via java main’s above:
then if you type
you will get the same behavior as an app that’s packaged with
which preserves the ordering and behavior of the maven classpath for our standalone camel boot microservice.
when you do a maven build you should see your app packaged up with its maven dependencies in a zip/tar.gz file. if you unpack that file, there’s a
file that can be used to boot up your camel microservice.
to convert this into a docker image, add the following
for more detailed instructions for setting this up and running it, please see the rider auto openshift documentation
packaging immutable karaf apps
if you’re doing karaf-based microservices, we will follow an analogous path as for camel boot. we’ll package our karaf app into an immutable karaf assembly with the
by adding the plugin to our maven build:
note, the example above builds a full distro of karaf with our microservice modules/apis and all dependencies baked into the distro. you can see in the config that we can control exactly what features, bundles, jre, etc that we want pre-baked into the distro.
should also be used to build the docker image for this module. again, check the
rider auto openshift documentation
for a full-blown, running example.
generate openshift/kubernetes component manifest
at the moment, fis has a couple options for generating the openshift/kubernetes manifest files (json/yaml – though at the moment only the json option is supported. in the
we support the yaml option too). to generate the replication controllers/pods/services we need to add the
and a few maven
with these pom.xml entries, we can do
and generate the kubernetes.json file to
we can also generate more advanced kubernetes manifest objects like persistentvolumes, secrets, multiple services, etc using a type-safe dsl for augmenting or generating the kubernetes.json file. see the rider-auto-file module for some examples and explanations of that.
features demonstrated in the rider auto microservices repo
please take a look at the rider auto project to see more detail about these features:
- generating the kubrenetes.json file with the fabric8 maven plugin
- adding persistentvolumes to the kubernetes.json file with a type-safe dsl
- building camel boot apps
- building immutable karaf apps
- discovering jboss amq in a kubernetes environment
- building docker images for camel boot and immutable karaf
- deploying apps to openshift
- how to merge multiple kubernets.json files into a single kubernetes.json file for “all in one” deployment
- connecting to local/remote docker daemon/openshift installations
- exposing soap and rest http services via kubernetes services
- using spring inside karaf
Published at DZone with permission of Christian Posta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.