Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Java DSL

Apache Camel offers a Java based DSL using the fluent builder style. The Java DSL is available by extending the RouteBuilder class, and implement the configure method.

This is best illustrate by an example. In the code below we create a new class called MyRouteBuilder that extends the org.apache.camel.builder.RouteBuilder from Camel.
In the configure method the Java DSL is at our disposal.

Code Block
java
java
import org.apache.camel.builder.RouteBuilder;

/**
 * A Camel Java DSL Router
 */
public class MyRouteBuilder extends RouteBuilder {

    /**
     * Let's configure the Camel routing rules using Java code...
     */
    public void configure() {

        // here is a sample which processes the input files
        // (leaving them in place - see the 'noop' flag)
        // then performs content based routing on the message using XPath
        from("file:src/data?noop=true")
            .choice()
                .when(xpath("/person/city = 'London'"))
                    .to("file:target/messages/uk")
                .otherwise()
                    .to("file:target/messages/others");
    }

}

In the configure method we can define Camel Routes. In the example above we have a single route, which pickup Files, (eg the from).

Code Block
        from("file:src/data?noop=true")

Then we use the Content Based Router (eg the choice) to route the message depending if the person is from London or not.

Code Block
            .choice()
                .when(xpath("/person/city = 'London'"))
                    .to("file:target/messages/uk")
                .otherwise()
                    .to("file:target/messages/others");
Include Page
Routes
Routes

See Also