A Simple Introduction to Apache Camel

DZone 's Guide to

A Simple Introduction to Apache Camel

A basic introduction to the Apache Camel integration tool. Stresses on the core concept more than the syntax.

· Java Zone ·
Free Resource

A "Stable, Consistent Architecture" is a myth. It can never be achieved. Over the years, each of us has come to accept this fact, and with a microservices architecture, it is a lot easier to live with this fact. But, that does pose a lot of other issues that we need to look at.

An important hurdle in this journey is that of application integration. A core tenet of the microservice architecture is that any interaction or integration between systems should be based on globally accepted standards rather than a mutually accepted protocol. If we build a system based on a protocol that is based on a simple mutual agreement between two developers, it can never work beyond those two developers. To enable a generic plug and play interface, the communication has to be based on globally accepted standards.

Apache Camel is one such standard, globally accepted way of integrating two systems — focused on Java. Apart from a simple protocol definition, it provides an implementation for several scenarios out of the box.

Important features of Apache Camel:

  • It is a light weight framework. 
  • It can be deployed on a variety of containers like Apache Tomcat.
  • It provides us with a number of built-in components that provide out of the box solutions for several common use cases.
  • It provides several different type converters for marshaling and unmarshalling the message during routing. 
  • It provides for Routes in a variety of domain-specific languages (DSL).


Apache Camel does not require any particular installation. You can just download the Jar files from the Website. Or simply include the dependency in the pom.xml file for a Maven project.


Sample Application

Let's now try to build a simple application that can demonstrate the power of Apache Camel. 

A simple scenario of integration is to join services generating and consuming files. Apache Camel can help us do this very easily. Just a few lines of code is enough to do the job.

Apache Camel defines a concept of a Camel Route. Essentially, a Route is an instruction to Camel on how messages should move from one point to another. In this example, we create a SimpleRouteBuilder class that can move files from SOURCE_FOLDER to TARGET_FOLDER.


Next, we create default camel context and load the route created in SimpleRouteBuilder. When Camel is started, it uses this to create a CamelContext object that contains the definition of the Route to be started.


When we run this MainApp.java. Any file in the source folder will be moved to the target folder.

What's the Big Deal?

This example is so trivial and simple that it can leave one wondering what is the big deal? There are hundreds of ways to move files from one location to another. Why do we need such an elaborate setup?

That is right. Moving files is not the point. Point is that the two microservices that produce and consume the file have no idea about what is going on behind the scene. Camel takes care of doing it seamlessly. And this is perhaps the simplest of routes we could create out of Camel. We can do a lot more with it. 

If required, Camel can help us transform the file on the fly. That sounds interesting? Yes, Apache Camel is quite interesting. 

camel, enterprise integraiton, java (programming lang..., microservice architecture

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}