Apache Camel is an incredible piece of software that allows you to easly define complex EIP workflows with absolute ease.

Wait! What?! Yeah, that was a fare amount of jargon.

I’m going to try break that down and show that hiding under all that stuffy looking jargon is a pretty jus framework for solving some very common problems.

Enterprise Integration Patterns

EIP or Enterprise Integration Patterns are a set of architectural design patterns for integrating disparate systems using asynchronous messaging. Originally set out in a book way back in 2003. Now that description still contained a lot of jargon, let’s try break that down a little further.

A design pattern according to the excellent Source Making:

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Design patterns are usually used to describe patterns to solve common problems that arise from writing Object-Orientated code. Architectural has been added to the description of this set of design patterns because they are try to solve a problem at a much higher level of abstration than

According to wikipedia a disparate system is:

In information technology, a disparate system or a disparate data system is a computer data processing system that was designed to operate as a fundamentally distinct data processing system without exchanging data or interacting with other computer data processing systems.

Well that’s dumb, obviously the first thing you’re going to need to do is make your CRM system, speak to your Invoicing system, speak to your Accounting system, and so on… In reality all computer systems are designed to exchange data with something at the end of the day. Whether via CSV files or DOS screens all systems have a way to input and extract data, it’s why they were built in the first place.

Asychronous Messaging is a robust method of comunication between two processes, where the processes can be two completely different systems. It is a fire and forget method of communication where one process or system will fire off a message and continue processing, not waiting for a response. The other system or systems will listen for the message and process them as the come.

Apache Camel

From Camel in Action:

Camel is an integration framework that aims to make your integration projects productive and fun…

What is Camel?

At the core of the Camel framework is a routing engine, or more precisely a routing-engine builder. It allows you to define your own routing rules, decide from which sources to accept messages, and determine how to process and send those messages to other destinations. Camel uses an integration language that allows you to define complex routing rules, akin to business processes.

ENTERPRISE INTEGRATION PATTERNS

Camel is heavily based on EIPs. Although EIPs describe integration problems and solutions and also provide a common vocabulary, the vocabulary isn’t formalized. Camel tries to close this gap by providing a language to describe the integration solutions. There’s almost a one-to-one relationship between the patterns described in Enterprise Integration Patterns and the Camel DSL.

So Camel is an integration framework that provides a DSL for describing EIPs!

Architecture

Its extensible and modular architecture allows you to implement and seamlessly plug in support for your own protocols, proprietary or not. These architectural choices eliminate the need for unnecessary conversions and make Camel not only faster but also very lean. As a result, it’s suitable for embedding into other projects that require Camel’s rich processing capabilities.

Again good ol’ Camel in Action descibes it best. Let’s dig a little deeper into the various components that make up Camel.

Camel Context

The CamelContext is the core service that runs Camel. This is where the RouteBuilders are registered that define the flow of data through the various Components and Endpoints. It implements a simple service interface with start and stop methods, which when the context is started each registered RouteBuilder is called and the Route is constructed.

Components

Components are the modules for supporting the various protocols and data types. Out of the box Camel comes with over 80 and many more are available from the community. These can either be explictitly registered in the CamelContext or injected via an IoC container. They act as Endpoint factories with the sole purpose of manageing the lifecycle of the Endpoint.

Endpoints

An Endpoint is Camel implimentation of the Message Endpoint pattern from EIP.

Message Endpoint code is custom to both the application and the messaging system’s client API. The rest of the application knows little about message formats, messaging channels, or any of the other details of communicating with other applications via messaging. It just knows that it has a request or piece of data to send to another application, or is expecting those from another application. It is the messaging endpoint code that takes that command or data, makes it into a message, and sends it on a particular messaging channel. It is the endpoint that receives a message, extracts the contents, and gives them to the application in a meaningful way.

Routing

Finally we have routing. Camel provides a DSL to define how a message travels through the systems various Components, Endpoints and Beans. This is the real beauty of Camel. The routes provide a simple and elegant way to compose the system out of the building blocks that come with Camel and the modular design makes it really easy to extend with your own Components.

And people have!

There are Components to integrate Camel with everything from email to S3 and every concievable thing inbetween. If for some reason you can’t find the Component you are looking for the modular nature of Camel’s architecture makes it super simple to write a component to full your need.

Conclusion

Apache Camel is jus! It makes integration a breeze with tried and tested methods from Enterprise Integration Patterns. If you ever in need of tool to ease the pain of integrating disparate, disfunctional systems (which let’s face it, there are a lot of them in the enterprise java world) Apache Camel is by far the best option.