The Camel DSL
All integration routes are defined in Camel through its own domain-specific language (DSL). This book presents the two main DSL flavors when discussing routing, the Java DSL, and the Spring XML DSL. OSGi Blueprint XML DSL is modeled after Spring, and is touched on lightly in this book. The Spring and OSGi Blueprint XML DSLs are collectively referred to as the XML DSL). There are other DSL variants available for defining Camel routes, including Groovy and Scala. For details on these see the following links:
- Groovy DSL: http://camel.apache.org/groovy-dsl.html
- Scala DSL: http://camel.apache.org/scala-dsl.html
Here is an example of a classic Content Based Router configured in Camel using both the XML and Java DSLs. You can find out more details on this in the Content Based Router recipe in Chapter 2, Message Routing.
In the XML DSL, you would write the routing logic as:
<route> <from uri="direct:start"/> <choice> <when> <simple>${body} contains 'Camel'</simple> <log message="Camel ${body}"/> </when> <otherwise> <log message="Other ${body}"/> </otherwise> </choice> <log message="Message ${body}"/> </route>
In the Java DSL, the same route is expressed as:
from("direct:start") .choice() .when().simple("${body} contains 'Camel'") .log("Camel ${body}") .otherwise() .log("Other ${body}") .end() .log("Message ${body}");
The decision of which flavor of DSL to use is largely a personal one, and using one does not rule out using another alongside it. There are pros and cons to each, though none are functional. All of the DSL variants allow you to fully use Camel's features.
DSL |
Pros |
Cons |
---|---|---|
Java |
|
|
XML |
|
|