0 Replies Latest reply on Jan 28, 2009 3:21 AM by Daniel Bevenius

    Drools RuleFlow integration

    Daniel Bevenius Master

      Kris Verlaenen has written an example integrating Drools RuleFlow with JBossESB that we have used as the basis of our integration. This post describes the work that has been done so fare.

      Communication from JBossESB to Drools RuleFlow is performed by using the org.jboss.soa.esb.ruleflow.action.BpmProcessor action. Examples of such communications are deploying a process, starting a process, and completing a process.
      Here is an example of deploying a process definition:

       <action name="create_new_process_instance" class="org.jboss.soa.esb.actions.ruleflow.BpmProcessor">
       <property name="command" value="deployProcess" />
       </action>
      

      This will deploy a process definition which is expected to be located in the default body location. This is the location that is used when you call:
      esbMessage.getBody().add("some data");

      This can be configured by specifying a different location by using the 'processLocation' property. You will also be able to specify a 'file' property if the process definition is to be picked up from the filesystem/classpath.
      Here is an example of a RuleFlow process definition:
      <?xml version="1.0" encoding="UTF-8"?>
      <process xmlns="http://drools.org/drools-5.0/process"
       xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
       xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
       type="RuleFlow" name="flow" [1]id="test-ruleflow" package-name="org.jboss.soa.esb" version="1.0" >
      
       <header>
       <variables>
       [2]<variable name="org.jboss.soa.esb.message.defaultEntry" >
       <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
       </variable>
       </variables>
       </header>
      
       <nodes>
       <workItem id="2" name="Service1" x="128" y="16" width="97" height="40" >
       <work [3]name="ESB Service" >
       <parameter name="Body">
       <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
       </parameter>
       <parameter name="ServiceName" >
       <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
       <value>TestService1</value>
       </parameter>
       <parameter name="CategoryName" >
       <type name="org.drools.process.core.datatype.impl.type.StringDataType" />
       <value>TestCategory</value>
       </parameter>
       </work>
       <mapping type="in" from="org.jboss.soa.esb.message.defaultEntry" to="Body" />
       <mapping type="out" from="Result" to="org.jboss.soa.esb.message.defaultEntry" />
       <onEntry>
       <action type="expression" dialect="java" >System.out.println("Entering Service1");</action>
       </onEntry>
       <onExit>
       <action type="expression" dialect="java" >System.out.println("Exiting Service1");</action>
       </onExit>
       </workItem>
      
       <end id="6" name="End" x="646" y="16" width="80" height="40" />
       <start id="1" name="Start" x="16" y="16" width="80" height="40" />
       </nodes>
      
       <connections>
       <connection from="1" to="2" />
       <connection from="2" to="6" />
       </connections>
      
      </process>
      

      [1]. This is the process 'id' which will be used later used to start the process.
      [2]. This is the variable name which will store the ESB Message payload. Notice the variable that is named after the default body location. This can also be a named body location as long as you use the same value for bodyLocations when starting the process.
      [3]. Work name specifies a WorkItemHandler and in this case we have named it "ESB Service". This name is used to register the ESBServiceWorkItemHandler with the process engine. ESBServiceWorkItemHandler is a WorkItemHandler that takes care of communication from a Drools RuleFlow to JBossESB. The registration of ESBServiceWorkItemHandler is done by the registerEsbWorkItemHandler() method in http://anonsvn.jboss.org/repos/labs/labs/jbossesb/workspace/dbevenius/ruleflow/product/services/jbrules/src/main/java/org/jboss/soa/esb/ruleflow/action/BpmProcessor.java .


      After a process has been deployed it can be started like this:
      <action name="create_new_process_instance" class="org.jboss.soa.esb.actions.ruleflow.BpmProcessor">
       <property name="command" value="startProcess" />
       <property name="processId" value="test-ruleflow"/>
      </action>
      

      Notice that we are specifying the 'processId' that we deployed above. We are not specifying a mapping for the ESB Message payload which means that the payload to be used will default to the default body location (org.jboss.soa.esb.message.defaultEntry).
      For more information about startProcess see: http://anonsvn.jboss.org/repos/labs/labs/jbossesb/workspace/dbevenius/ruleflow/product/services/jbrules/src/main/java/org/jboss/soa/esb/ruleflow/action/commands/StartProcess.java

      Finally, there is a command to complete a work item:
      <action name="action" class="org.jboss.soa.esb.ruleflow.action.BpmProcessor">
       <property name="command" value="completeWorkItem" />
      </action>
      


      Note that this version was built using drools-5.0.0.M4 and is very much a work in progress. We are posting this to get some early feedback and comments from anyone that is interested.

      Links:
      Workspace: http://anonsvn.jboss.org/repos/labs/labs/jbossesb/workspace/dbevenius/ruleflow
      Quickstart: http://anonsvn.jboss.org/repos/labs/labs/jbossesb/workspace/dbevenius/ruleflow/product/samples/quickstarts/bpm_orchestration_flow_1/
      Unittest: http://anonsvn.jboss.org/repos/labs/labs/jbossesb/workspace/dbevenius/ruleflow/product/services/jbrules/src/test/java/org/jboss/soa/esb/ruleflow/action/BpmProcessorUnitTest.java


      /Daniel