In this blog, we are going to learn an introduction to Apache Camel. It is an integration library for Java. It provides a set of Java APIs which help you integrate and process data between different computer systems. In other words, Camel is like the glue between different applications
You can think of Camel as a plumbing toolkit for your data. Camel can take data from one application, and pipe it to another. Along the way, the data can be changed, transformed, or sent through other pipes. Included in your plumbing toolkit is a range of adaptors (these are called Components in Camel-speak) that fit all kinds of applications and software systems. Components in Camel help you to integrate data from lots of different places — like data in web services, or data in files on disk. You can even connect Camel to web apps, like Twitter and Salesforce.
With your Camel toolkit at your disposal, it’s up to you how you choose to build the plumbing
Apache Camel in 5 points
Here are some high-level pieces of information and reasons to befriend a Camel!
Camel is written in Java
Since Apache Camel is written in Java, you have the full power of Java at your disposal. You can embed it in your existing applications, integrate Camel with your own Java code, and much more.
The source code is completely open
Want to know exactly how Camel works? Just grab the Camel source code from GitHub and have a look around. Everything is there. Nothing is hidden away in proprietary code.
It’s not just for web services
It’s a general integration framework. You can use Camel to interact with web services, but it’s capable of far more than that.
It comes with a huge library of components
If you can think of an application or service you’d like to connect to, there’s probably a Camel component for it. You can do everything from storing files in Dropbox, to sending a tweet. You can also write your own component, and contribute it to the community.
Apache Camel is well and truly mature and has a great community behind it. It also forms the foundation of some commercial integration products, like Red Hat Fuse and Talend ESB. This means that you can always get support for Camel if you need it, whether paid commercial support or community help.
What is Apache Camel used for?
Whenever you need to move data from A to B, you can probably use Apache Camel. Here are some scenarios, to give you an idea of what you can build with Camel. You can implement all of these with Camel — usually with just a few lines of code:
1 Pick up invoices from your corporate file server and email them to customers
2 Move documents from your hard disk into Google Drive
3 Take incoming customer order messages from a queue and use them to invoke a web service
4 Turn some XML documents into CSV files
What’s in the box?
Apache Camel is not a program that you install. It’s a library for Java developers, distributed as a set of JAR files that you can include in your own projects. Most developers will get started with Camel by adding it as a dependency using Maven, and we’ll see how to do this shortly.
But if you were to download the binary distribution of Camel from the Camel website, what would be in the box?
The core functionality of Camel is distributed as a set of about 12 JAR files. This includes the Camel APIs, the Camel runtime engine, and functionality for runtime management of your Camel applications.
To allow Camel to connect to external systems, Camel needs to be given superpowers, by adding components. Each component extends Camel with functionality to interact with a third-party system or API. Most components are distributed in their own JAR. There are over 300 components to choose from.
Platform support JARs
These JAR files provide the functionality to help Camel run on different platforms, like Spring Boot, or Apache Karaf (OSGi).
In this section, we’ll look at each of the main concepts of Apache Camel.
Camel provides a runtime engine, called the Camel Context, which runs your integrations. It’s kind of like a mini-application server, embedded inside your Java application. The Camel Context runs your integrations and is generally responsible for moving data through the system. The simplest way of starting Camel is to create an instance of DefaultCamelContext (which implements the CamelContext interface) and call the start method:
Starting the CamelContext
CamelContext context = new DefaultCamelContext();
One of the main reasons to use Camel is when you want to integrate systems and applications together. To use the same plumbing analogy from earlier in this section, we want to use Camel so that we can run pipelines that move data from one place to another. In Camel, these integration pipelines are called Routes. A route usually consists of a series of steps. The first step receives or fetches some data, and then the data is passed through subsequent steps to the end of the route.
A simple route definition looks something like this (in Camel’s Java syntax):
In Camel, an Endpoint is an interface through which Camel exchanges a message with another system. Camel can receive a message from an Endpoint, or send a message to an Endpoint.
To allow Camel to create an Endpoint, it uses a Component. A Component is simply a specialized plug that allows you to connect to an external system, such as a file on disk, a mailbox, or an application like Dropbox or Twitter.
Camel is designed to be added to your existing Java application. Or, you can start with Camel by creating a new project, using one of the templates provided by the Camel community. For more information visit: https://camel.apache.org/manual/book-getting-started.html