我在此图片中描述了一个流程:
如果两个事件消息都触发,则会在AND Converge Gateway上控制以结束进程或记录字符串。 如果只有其中一个触发,则进程等待几秒钟,然后将变量检入消息数据,以确定它是否必须结束或记录。
事件消息的属性:
EventType a_fall_message
Name A message
Scope external
VariableName a_message
写入OR网关约束的代码结束:
return a_message.getConfidenceIndex() < 0.8;
编写到Converge Gateway的OR网关约束中的代码:
return a_message.getConfidenceIndex() >= 0.8;
简单的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();
}
使用简单的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;
}
}
所以我需要访问Message Event数据变量a_message。当我玩这个简单的项目时,我在consolle上看到了这条消息:
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)
你有什么建议吗?
答案 0 :(得分:0)
如果没有看到实际的bpmn2 xml,不确定发生了什么,但似乎你在某处使用了名为'cnr_message'和'emt_message'的变量(在动作脚本或条件中),但你还没有将它们定义为过程变量?
编译错误并没有直接抱怨a_message所以如果你把它定义为一个过程变量,乍一看似乎正常工作。