2 Replies Latest reply on Feb 27, 2012 9:28 AM by Dennis Buttery

    Drools rules based on ESB Message property

    Dennis Buttery Newbie

      Hi all,

       

         After much consternation and fruitless tail-chasing I am hoping to find a clear-cut, to-the-point example of writing Drools rules based on a property of a ESB message.

       

         Here is the snippet from my jboss-esb.xml that defines the CBR action:

       

           <!-- Route to different service based on message property -->

                      <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">

                          <property name="ruleSet"      value="META-INF/MyCBRRules.drl"/>

                          <property name="ruleReload"   value="true"/>

                          <property name="destinations">

                              <route-to destination-name="service1" service-category="Cat1" service-name="Svc1"/>

                              <route-to destination-name="service2" service-category="Cat2" service-name="Svc2"/>

                              <route-to destination-name="service3" service-category="Cat3" service-name="Svc3"/>

                          </property> 

                          <property name="object-paths">

                              <object-path esb="properties.DestService" />

                          </property>   

                      </action>

        

          It is my understanding that using the <object-paths> in this way would present the 'DestService' property of my ESB message to the rules set.

       

          So...  My question is what exactly is the syntax to be used in the .drl file to allow for rule matching on the value of the ESB property?

       

          Sample .drl file below:

       

      #===================================================

      # Routing rules for ESB messages.

      #===================================================

      package com.jboss.soa.esb.routing.cbr

       

      #list any import classes here.

      import org.jboss.soa.esb.message.Message;

       

      #declare any global variables here

      global java.util.List destinations;

       

      rule "Service 1 Routing Rule"

          when

              ????  Syntax here to match against ESB property value ????

          then

              System.out.println("Routing to Service 1");

              destinations.add("service1");

      end

       

      rule "Service 2 Routing Rule"

          when

              ????  Syntax here to match against ESB property value ????

          then

              System.out.println("Routing to Service 2");

              destinations.add("service2");

      end

       

      rule "Service 3 Routing Rule"

          when

              ????  Syntax here to match against ESB property value ????

          then

              System.out.println("Routing to Service 3");

              destinations.add("service3");

      end

       

       

      Thanks!

      -Dennis