Image Blog Introduction Enterprise Integration Patterns Apache Camel
November 8, 2018

Introduction to Enterprise Integration Patterns and Apache Camel


In this blog, we discuss enterprise integration patterns using Camel (Apache). You'll get enterprise integration patterns examples to help you use them.

What Are Enterprise Integration Patterns?

Enterprise integration patterns are patterns used to design, build, and deploy messaging solutions.

Why Use Enterprise Integration Patterns With Camel (Apache)

In my opinion, Camel is one of the best ways to create sophisticated enterprise integration workflows. By combining a component-driven approach with an easy-to-understand syntax, Camel allows developers to federate various applications with minimal code.

Camel was designed as a programmatic implementation of Enterprise Integration Patterns (EIP). As an architectural design pattern, EIP defines code-agnostic workflows for common business tasks.

For instance, the “Dynamic Router” pattern defines a messaging workflow in which a characteristic of a message is used to make a decision on where to send that message. Visually, the pattern is defined as such:

Enterprise Integration Patterns

Most enterprise developers have written logic like this. In the above image, messages with a green square characteristic are pushed to the “widget inventory”, whereas ones with an orange diamond characteristic are pushed to the “gadget” inventory. Another EIP is the “Content Enricher” pattern:

Enterprise Integration Patterns 2

In this pattern, we begin with a basic message. We then query some sort of resource, perhaps a database or a file server, and enrich the message with data from that resource. Again, most developers have written similar logic. So, the goal of EIP is to create a common vocabulary and set of workflow actions that can be combined together to create sophisticated business process.

Build Your Open Source Stack

Apache Camel is likely just one piece of your enterprise open source stack. Use the OpenLogic Stack Builder to build your stack. You'll get a report complete with recommendations from open source experts to help you improve your stack.

Build Your Stack

Enterprise Integration Patterns Examples With Apache Camel

Here are some enterprise integration patterns examples using Apache Camel.

Why Apache Camel?

So what does any of this have to do with Apache Camel? Well, basically everything!

Camel provides a language that can build these patterns using a basic syntax. It takes a message-driven approach to integration, where messages contain data payloads that can be shuttled around through various endpoints.

The endpoints themselves are implemented using Camel Components, and there are a lot of them!

Camel routes are highly portable. They can be run standalone, deployed in a servlet container, wrapped as OSGI blueprints, and more!

Camel Syntax

Camel’s syntax is inspired by the UNIX pipeline.

In UNIX, we might execute something like ps -fe | grep foo. When we run this command, the output of the ps command becomes the input to the grep command. We “pipe” the output of one command into the input of another command.

Camel chains these actions together in an object called an Exchange, which consists of an input message (called the “In” message), some sort of processor (like a component, for instance) and possibly an output or “Out” message if the processor is meant to provide a synchronous response.

A series of Exchange state changes creates a Camel Route.

Camel Route

The magic here is that these processors can be anything. They can be an integration component, they can be a custom processor, and they can be some sort of data transformer. The sky is the limit!

Camel Route

Consider the following Camel Route:

Example Camel Route :: FileXlateThis is a message that says '${body}' that came from a filename of ${headers.CamelFileName}

This route begins using Camel’s “file” component, which allows the route to interact with a local file system.

In this case, we’re creating a file consumer that will watch a directory called “/tmp/InputFiles.” Any time a new file is created in this directory, the contents of that file will become the first input message on the route.

We then perform a simple transform using the reserved command, which transforms the body of the message. In this case, we’re using one of Camel’s built-in scripting languages, , to provide access to the message contents using the ${} property syntax.

Components tend to append relevant headers to messages that move through them. The file component provides many headers, and a useful one is the CamelFileName header which retains the name of the file that is being processed.

Finally, we send that payload to the Camel “activemq” component, which allows for integration with the ActiveMQ message broker.

So, effectively three small blocks of code, we create a file consumer, transform the message payload, and create a JMS producer which will push the file’s contents as a JMS message to an ActiveMQ broker.

Powerful stuff!

Leverage Enterprise Integration Patterns Examples With OpenLogic

There’s a lot to this language and this post barely scratches the surface of what can be achieved using this valuable framework. 

If you want to truly leverage enterprise integration patterns examples, such as Apache Camel, you'll need to enlist the help of the experts. Luckily, you can do just that with the OpenLogic team.

OpenLogic provides comprehensive support and training — including on enterprise integration patterns with Camel. 

To learn more about how OpenLogic can help you, get in touch with our experts today. 

Talk to an Expert