All, I am learning Drools 6.1 and I need to use rule flow. I have the Drools 6.1 distribution final installed and installed Eclipse Drools plugin.
I created sample rules and tests, everything worked fine. Then I added a rule flow, which is a file ending with "bpmn". So I think this is a drools jbpm artifact. I configured the right "ruleflow-group" value in my rules. When I run the test, I got exception like below:
java.lang.IllegalArgumentException: Unable to instantiate service for Class 'org.drools.compiler.compiler.BPMN2ProcessProvider'
THen I added 4 JARs from the droolsjbpm-integration-distribution-6.1.0.Final zip file to the drools project:
<classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-bpmn2-6.1.0.Final.jar"/>
<classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-flow-builder-6.1.0.Final.jar"/>
<classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-workitems-6.1.0.Final.jar"/>
<classpathentry kind="lib" path="D:/Tools/drools-distribution-6.1.0.Final/binaries/jbpm-flow-6.1.0.Final.jar"/>
no more runtime exception. I was able to invoke the rule flow from Java code but none of the rules in the ruleflow-group was triggered. If I use kSession.fireAllRules() to skip rule flow, the rules were executed. I wonder if there is anything missing. Below are sections of my code.
Thanks.
Daniel
Sample.drl
rule "AnyTime"
ruleflow-group "ruleTask1"
salience 10000
then
System.out.println( "Rule Flow Triggered");
System.out.println( "Output Size is " + list.size());
end
Java code:
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules-stateful");
List list = new ArrayList();
kSession.setGlobal("list", list);
kSession.addEventListener( new DefaultAgendaEventListener() {
public void afterMatchFired(AfterMatchFiredEvent event) {
super.afterMatchFired( event );
System.out.println( event );
}
});
kSession.addEventListener( new DebugRuleRuntimeEventListener() );
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
FactHandle messageHandle = kSession.insert(message);
//int ruleFired = kSession.fireAllRules();
kSession.startProcess("mainFlow1");
System.out.println("rules fired and In the output, the list size is " + list.size());
System.out.println("Message status is " + message.getStatus() + message.getMessage());
kSession.delete(messageHandle);
kSession.dispose();