I have a flow described in this image:
if both event message fire, there's a control on the AND Converge Gateway to end the process or to log a string. In case of only one of them fire, the process wait few seconds then check a variable into message data to decide if it must end or log instead.
Properties of the event message:
EventType a_fall_message
Name A message
Scope external
VariableName a_message
Code written into OR Gateway constraint to End:
return a_message.getConfidenceIndex() < 0.8;
Code written into OR Gateway constraint to Converge Gateway:
return a_message.getConfidenceIndex() >= 0.8;
The simple java main:
public static void main(String[] args) throws Exception {
KnowledgeBase knowledgeBase = readKnowledgeBase("messagetestevent.rf");
StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
Map<String, Object> parameterMap = new HashMap<String, Object>();
Integer i = 2;
parameterMap.put("groupId", i);
SimpleWorkItemHandler handler = new SimpleWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Log", handler);
ProcessInstance a = ksession.startProcess("com.droolstest.messagetestevent", parameterMap);
a.signalEvent("a_fall_message", new FallMessage(0.7));
a.signalEvent("b_fall_message", new FallMessage(0.7));
ksession.fireAllRules();
}
private static KnowledgeBase readKnowledgeBase(String name) throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(name), ResourceType.DRF);
return kbuilder.newKnowledgeBase();
}
with the simple POJO:
public class FallMessage {
double confidenceIndex;
public FallMessage(double c) {
confidenceIndex = c;
}
public double getConfidenceIndex() {
return confidenceIndex;
}
public void setConfidenceIndex(double confidenceIndex) {
this.confidenceIndex = confidenceIndex;
}
}
So I need to access to the Message Event data variable a_message. When i play this simple project I see on the consolle this message:
Process Compilation error : org.drools.lang.descr.ProcessDescr@10e35d5
com/droolstest/Process_com_droolstest_0.java (8:357) : b_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (18:627) : b_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (28:897) : b_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (28:939) : a_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (38:1209) : b_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (38:1251) : a_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (48:1521) : a_message cannot be resolved
com/droolstest/Process_com_droolstest_0.java (58:1791) : a_message cannot be resolved
Exception in thread "main" java.lang.IllegalArgumentException: Could not parse knowledge.
at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:58)
at com.droolstest.DroolsTest.readKnowledgeBase(DroolsTest.java:39)
at com.droolstest.DroolsTest.main(DroolsTest.java:17)
Have you got any suggestions?
Not sure what's happening exactly without seeing the actual bpmn2 xml, but it seems you're using variables called 'cnr_message' and 'emt_message' somewhere (in action scripts or conditions) but you haven't defined them as a process variable?
The compilation error is not directly complaining about a_message so if you defined that as a process variable, that seems to be working correctly at first glance.