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.

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

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

Routes

Camel supports the definition of routing rules using a Java DSL (domain specific language) which avoids the need for cumbersome XML using a RouteBuilder.

For example a simple route can be created as follows.

As you can see from the above Camel uses URIs to wire endpoints together.

URI String formatting

Available as of Camel 2.0

If you have endpoint URIs that accept options and you want to be able to substitute the value, e.g. build the URI by concat the strings together, then you can use the java.lang.String.format method. But in Camel 2.0 we have added two convenient methods in the Java DSL so you can do fromF and toF that uses String formatting to build the URI.

Filters

You can combine simple routes with filters which can be arbitrary Predicate implementations.

Choices

With a choice you provide a list of predicates and outcomes along with an optional default otherwise clause which is invoked if none of the conditions are met.

Using a custom processor

Here is an example of using a custom Processor

You can mix and match custom processors with filters and choices.

Interceptors

Here is an example of adding a few custom InterceptorProcessor objects to a processing pipeline:

When you start defining and interceptor stack with intercept(), you must follow up with the subsequent .target() so that the target of the interceptor stack is properly registered.

See Also

© 2004-2014 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram