LibraryToggle FramesPrintFeedback

Content-based Router


A content-based router enables you to route messages to the appropriate destination, where the routing decision is based on the message contents. This pattern maps to the corresponding content-based router pattern in Apache Camel.

Figure 48. Content-based Router Pattern

Content-based router pattern

Example ServiceMix EIP route

Example 14 shows how to define a content-based router using the ServicMix EIP component. If a test:echo element is present in the message body, the message is routed to the http://test/pipeline/endpoint endpoint. Otherwise, the message is routed to the test:recipients endpoint.

Example 14. ServiceMix EIP Content-based Route

<eip:content-based-router service="test:router" endpoint="endpoint">
        <eip:xpath-predicate xpath="count(/test:echo) = 1" namespaceContext="#nsContext" />
        <eip:exchange-target uri="endpoint:test:pipeline:endpoint" />
      <!-- There is no predicate, so this is the default destination -->
        <eip:exchange-target service="test:recipients" />

Equivalent Apache Camel XML route

Example 15 shows how to define an equivalent route using Apache Camel XML configuration.

Example 15. Apache Camel Content-based Router Using XML Configuration

  <from uri="jbi:endpoint:"/>
      <xpath>count(/test:echo) = 1</xpath>
      <to uri="jbi:endpoint:"/>
      <!-- This is the default destination -->
      <to uri="jbi:service:"/>

Equivalent Apache Camel Java DSL route

Example 16 shows how to define an equivalent route using the Apache Camel Java DSL.

Example 16. Apache Camel Content-based Router Using Java DSL

    choice().when(xpath("count(/test:echo) = 1")).to("jbi:endpoint:").

Comments powered by Disqus