官术网_书友最值得收藏!

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:

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.

主站蜘蛛池模板: 灵川县| 肥乡县| 将乐县| 石嘴山市| 英超| 宿迁市| 太谷县| 孙吴县| 孙吴县| 疏附县| 武冈市| 郯城县| 奉贤区| 呼和浩特市| 福安市| 丰宁| 雷州市| 肃宁县| 富民县| 雅安市| 青阳县| 辛集市| 辰溪县| 清原| 获嘉县| 湾仔区| 临江市| 买车| 桐柏县| 甘洛县| 湖北省| 盱眙县| 宁化县| 永川市| 图木舒克市| 桃园市| 小金县| 林州市| 东明县| 谷城县| 兖州市|