<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <h3 class="post-title entry-title"><a
href="http://blog.athico.com/2011/01/drools-content-based-routing-with-camel.html">http://blog.athico.com/2011/01/drools-content-based-routing-with-camel.html</a><br>
    </h3>
    <h3 class="post-title entry-title"><a
href="http://blog.athico.com/2011/01/drools-content-based-routing-with-camel.html">Drools
        Content Based Routing with Camel (John Ellis)</a>
    </h3>
    John Ellis has done a nice writeup of his work on improving Drools
    to work with Camel for CBR. You'll need to use the latest version of
    Drools from trunk, which can be found in the maven repository that's
    5.2.0-SNAPSHOT, <a
href="https://repository.jboss.org/nexus/content/groups/public/org/drools/">https://repository.jboss.org/nexus/content/groups/public/org/drools/</a>.<br>
    <br>
    For bonus points I'd love to see a further Drools and Camel tutorial
    around OSGi's EventAdmin, <a href="http://">http://camel.apache.org/eventadmin.html</a>.<br>
    <br>
    One of Camel's greatest strengths is the explicit support for <a
      href="http://www.eaipatterns.com/toc.html">Enterprise Integration
      Patterns</a>. Drools itself is particularly well suited to work
    alongside Camel to implement two commonly used integration patterns:
    the Content Based Router and the Dynamic Router. Both patterns
    leverage the ability of a Drools Endpoint to rapidly evaluate
    properties of a message, while the Dynamic Router can also integrate
    the Drools Policy as a dynamic rule based on feedback from a control
    channel.
    <p style="margin-bottom: 0cm;">The Camel routes required for message
      routing do not differ much from the previous Drools Endpoint
      example. You may even be able to omit the Drools Policy if you
      wish to inspect only the headers of messages being routed instead
      of interrogating the body of each message. For example, a DRL
      could be defined that takes action on inbound messages such as:<br>
      <br>
    </p>
    <pre class="brush:drl">import org.apache.camel.Message;
rule "WriteOperations"
when
    $message : Message(headers["OPERATION"] == "WRITE");
then
    $message.setHeader("routingSlip", "activemq:queue:op.write");
end

rule "ReadOperations"
when
    $message : Message(headers["OPERATION"] == "READ");
then
    $message.setHeader("routingSlip", "activemq:queue:op.read");
end</pre>
    <br>
    Example 1: DRL for Routing Based on Message Headers<br>
    <br>
    Here the custom header &#8220;OPERATION&#8221; is evaluated to see if it is set
    to the value &#8220;WRITE&#8221; or &#8220;READ.&#8221; Depending on the value of this
    header, a routing slip is defined for the message. The Routing Slip
    is another Enterprise Integration Pattern supported by Camel that
    may contain one or more URIs. The message is then sequentially sent
    to each URI defined.<br>
    <br>
    The Camel routing itself is simply defined as:<br>
    <br>
    <pre class="brush:drl">&lt;route&gt;
    &lt;from uri="activemq:queue:router"/&gt;
    &lt;to uri="drools:brokerNode/cbrKSession?action=insertMessage"/&gt;
    &lt;routingSlip uriDelimiter="#"&gt;
        &lt;header&gt;routingSlip&lt;/header&gt;
    &lt;/routingSlip&gt;
&lt;/route&gt;</pre>
    <br>
    Example 2: Camel Routes for Content Based Routing<br>
    <br>
    Here we explicitly inform Camel that routing slips are defined as
    values within the &#8220;routingSlip&#8221; header and each URI is delimited by
    a # character. The headers set within the DRL are then interpreted
    as each message exits the Drools endpoint.<br>
    <br>
    Content based routing with a Drools Endpoint offers several
    advantages over Camel's default implementation. The DRL format
    itself allows routing to be specified more succinctly than Sprint
    DSLs or Camel RouteBuilders. Conditional operations are also
    evaluated more efficiently within Drools and are thread-safe,
    allowing a high volume of messages to be routed concurrently.
  </body>
</html>