Camel Integration Framework

Camel is an integration framework that aims to make your integration projects pro- ductive and fun.

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 com- plex routing rules, akin to business processes.

One of the fundamental principles of Camel is that it makes no assumptions about the type of data you need to process. This is an important point, because it gives you, the developer, an opportunity to integrate any kind of system, without the need to convert your data to a canonical format.

Camel offers higher-level abstractions that allow you to interact with various sys- tems using the same API regardless of the protocol or data type the systems are using. Components in Camel provide specific implementations of the API that target differ- ent protocols and data types. Out of the box, Camel comes with support for over 80 protocols and data types. Its extensible and modular architecture allows you to imple- ment 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. Other open source projects, such as Apache ServiceMix and ActiveMQ, already use Camel as a way to carry out enterprise integration.


  • Routing and mediation engine
  • Domain-specific language (DSL)
  • Payload-agnostic router
  • POJO model
  • Automatic type converters
  • Test kit
  • Enterprise integration patterns (EIPs)
  • Extensive component library
  • Modular and pluggable architecture
  • Easy configuration
  • Lightweight core
  • Vibrant community



public class FileCopierWithCamel {
    public static void main(String args[]) throws Exception {


    CamelContext context = new DefaultCamelContext();
    context.addRoutes(new RouteBuilder() {
        public void configure() {

} });


Sample to copy file from one location to another using camel 


The abstract org.apache.camel.builder.RouteBuilder class in Camel is one that you’ll see frequently. You’ll need to use it any time you create a route in Java.

To use the RouteBuilder class, you extend a class from it and implement the con- figure method, like this:

        class MyRouteBuilder extends RouteBuilder {
            public void configure() throws Exception {

… }


You then need to add the class to the CamelContext with the addRoutes method:

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new MyRouteBuilder());

Alternatively, you can combine the RouteBuilder and CamelContext configuration by adding an anonymous RouteBuilder class directly into the CamelContext, like this:

        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {

} });



The Processor interface in Camel is an important building block of complex routes. It’s a simple interface, having a single method:

public void process(Exchange exchange) throws Exception;

This gives you full access to the message exchange, letting you do pretty much what- ever you want with the payload or headers.

All EIPs in Camel are implemented as processors. You can even add a simple pro- cessor to your route inline, like so:

process(new Processor() {
    public void process(Exchange exchange) throws Exception {
        System.out.println("We just downloaded: "
            + exchange.getIn().getHeader("CamelFileName"));

} }).


Using Spring with Camel

To load up a CamelContext in Spring, you can do the following:

<beans xmlns=”; xmlns:xsi=”; xsi:schemaLocation=””&gt;

<camelContext xmlns=""/>




          <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
            <property name="connectionFactory">
              <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="vm://localhost" />


          <camelContext xmlns="">
              <to uri="jms:incomingOrders"/>

This will automatically start a SpringCamelContext, which is a subclass of the DefaultCamelContext you used for the Java DSL.


content-based router

As the name implies, a Content-Based Router (CBR) is a message router that routes a message to a destination based on its content. The content could be a message header, the payload data type, part of the payload itself—pretty much anything in the message exchange.

using CBR


.when(predicate) .to(“jms:xmlOrders”)

.when(predicate) .to(“jms:csvOrders”);

You may have noticed that we didn’t fill in the predicates required for each when method. A predicate in Camel is a simple interface that only has a matches method:

public interface Predicate {
    boolean matches(Exchange exchange);




Often in enterprise applications you’ll need to send a copy of a message to several dif- ferent destinations for processing. When the list of destinations is known ahead of time and is static, you can add an element to the route that will consume messages from a source endpoint and then send the message out to a list of destinations


With Camel, you can use the multicast method in the Java DSL to implement this


from("jms:xmlOrders").multicast().to("jms:accounting", "jms:production");


Sending messages in parallel using the multicast involves only one extra DSL method: parallelProcessing. Extending the previous multicast example, you can add the parallelProcessing method as follows:

    .to("jms:accounting", "jms:production");

you can take advantage of the stopOnException feature of the multicast. When enabled, this feature will stop the multicast on the first exception caught, so you can take any necessary action.

To enable this feature, use the stopOnException method as follows:

    .to("jms:accounting", "jms:production");

WireTap - to audit orders

By using the wireTap method in the Java DSL, you can send a copy of the exchange to a secondary destination without affecting the behavior of the rest of the route:


Data Transformation with Camel 

Data transformation is a broad term that covers two types of transformation:

  • Data format transformation—The data format of the message body is transformed from one form to another. For example, a CSV record is formatted as XML.
  • Data type transformation—The data type of the message body is transformed from one type to another. For example a java.lang.String is transformed into a javax.jms.TextMessage.