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 have a J2EE container or a 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.Its divided into three parts:

  • Scheme:It denotes which Camel component handles that type of endpoint. In this case the file component will be used and it will create an endpoint based on the remaining parts of the URI
  • Context path: it tells the component that the starting folder is data/inbox
  • Options: indicates that files should be polled every 5seconds.

    Routes

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

  • Decide dynamically what server a client will invoke
  • Provide a flexible way to add extra processing
  • Allow for clients and servers to be developed independently
  • Foster better design practices by connecting disparate systems that do one thing well
  • Enhance features and functionality of some systems (such as message brokers and ESBs)
  • 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:

  • Create a CamelContext object.
  • Add endpoints - and possibly Components to the CamelContext object.
  • Add routes to the CamelContext object to connect the endpoints.
  • Invoke the start() operation on the CamelContext object. This starts Camel-internal threads that are used to process the sending, receiving and processing of messages in the endpoints.
  • 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: