How Apache Camel works

Apache Camel is an open source integration framework based on Enterprise Integration Patterns (EIPs) with comprehensive integration with Java and Spring.

Camel focuses on making integration easier and more accessible by providing

Using Camel we can implement routing and mediation rules in either

Camel does not bring its own J2EE container or a full message bus implementation including messaging services. It can be deployed into ServiceMix together with messaging facilities like ActiveMQ, or embedded in a Web Application and deployed in a J2EE container providing JMS capabilities. Camel is not an Enterprise Service Bus (ESB), although some call Camel a lightweight ESB because of its basic support for routing, transformation and monitoring.

Components

Components are the extension point in Camel to add connectivity to other systems.

Endpoints

Endpoints represents the end of a channel through which a system can send or receive messages. Usually, Endpoints are created by Components and they are usually referred to via their URIs.

file:data/inbox?delay=5000

The previous example shows an example of endpoint definition. It is divided into the following three parts:

Routes

By decoupling clients from servers, and producers from consumers, routes can:

Each route in Camel has a unique identifier that's used for logging, debugging, monitoring, and starting and stopping routes. Routes also have exactly one input source for messages, so they're effectively tied to an input endpoint. To define a route, a DSL is used.

Domain-Specific Language (DSL)

Camel uses a Java Domain Specific Language or DSL for creating Enterprise Integration Patterns or Routes. Camel provides multiple DSL languages, so you could define the same route using a Spring based XML configuration as well as a Scala DSL. The example below shows a route definition using Spring DSL.

<route>
  <from uri="file:data/inbox"/>
  <filter>
    <xpath>/order[not(@test)]</xpath>
    <to uri="jms:queue:order"/>
  </filter>
</route>

CamelContext

A CamelContext object represents the Camel runtime system. Typically, we have one CamelContext object in an application. A typical application executes the following steps:

Eventually invoke the stop() operation on the CamelContext object. Doing this gracefully stops all the endpoints and Camel-internal threads.

Processor

Processors are used to manipulate and mediate messages in between Endpoints. The Processor interface represents a class that processes a message. The signature of this interface is shown below.

package org.apache.camel;

public interface Processor {
   void process(Exchange exchange) throws Exception;
}

End-to-end Interaction

The following diagram shows how the components described above interact with each other:

Components
Figure: Interaction of components