1

我在这张图片中描述了一个流程:

流动

如果两个事件消息都触发,AND Converge Gateway 上有一个控件来结束进程或记录字符串。如果只有其中一个被触发,进程会等待几秒钟,然后将变量检查到消息数据中,以决定它是否必须结束或记录。

事件消息的属性:

    EventType      a_fall_message
    Name           A message
    Scope          external
    VariableName   a_message

将代码写入 OR 网关约束以结束:

return a_message.getConfidenceIndex() < 0.8;

写入 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。当我玩这个简单的项目时,我在控制台上看到这条消息:

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)

你有什么建议吗?

4

1 回答 1

0

在没有看到实际的 bpmn2 xml 的情况下不确定到底发生了什么,但似乎您在某处(在动作脚本或条件中)使用了名为“cnr_message”和“emt_message”的变量,但您尚未将它们定义为流程变量?

编译错误并没有直接抱怨 a_message 所以如果你将它定义为一个流程变量,乍一看似乎工作正常。

于 2013-09-06T12:14:46.800 回答