议程组在 Drools 中未按预期工作

Agenda groups not working as expected in Drools

现在,在我的 drools 项目中,我在单独的 DRL 文件中有两组规则,这些规则按议程组分开。对于议程组 "preCheck",我将该议程组中的每条规则的自动对焦设置为 true。示例:

rule "preCheckDuplicate"
    agenda-group "preCheck"
    auto-focus true
    no-loop true
    salience 50
    when
        $f : IngestFileMetadata(isDuplicate.equalsIgnoreCase("True"))
    then
        $f.setIsDuplicate("True");
end

对于另一个议程组 - "defaultRules" - 规则没有设置自动焦点属性。示例:

rule "duplicate file default"
    agenda-group "defaultRules"
    activation-group "isDuplicate"
    no-loop true
    salience 0
    when
        $f : IngestFileMetadata(isDuplicate.equals("True"))
    then
        insert(createResponse($f));
end

当通过其余 API 调用规则时,我还试图通过 JSON 负载将焦点设置到 "preCheck" 议程组。示例:

{
  "lookup": "defaultStatelessKieSession",
  "set-focus": "preCheck",
  "commands": [
    {
      "insert": {
        "out-identifier": "IngestFileMetadata",
        "return-object": "true",
        "entry-point": "DEFAULT",
        "object": {
          "com.hms.ingestion.rules.IngestFileMetadata": {
              * * * * * data attributes here * * * * *
          }
        }
      }
    },
    {
      "fire-all-rules": {"out-identifier": "fired"}
    },
    {
      "query": {"name": "rulesResponses", "out-identifier": "rulesResponses"}
    }
  ]
}

但是,当规则被执行时,"defaultRules" 议程组中的规则似乎首先被评估。我不知道为什么。我对 drools 比较陌生,所以我完全有可能没有正确理解议程组的概念,但我确信这种设计将确保 "preCheck" 规则首先评估。

任何人都可以提供任何关于为什么没有发生这种情况的见解吗?如果我需要提供更多详细信息,我可以。

提前致谢。

Agenda groups allow you to place rules into groups, and to place those groups onto a stack. The stack has push/pop behavior. Before going into how to use agenda group firstly, I want to say that configuring agenda group is depends on what type of KieSession you are using in your rule engine. For stateful Session, you can directly configure it by calling ksession.getAgenda().getAgendaGroup( "preCheck" ).setFocus();. For Stateless Session, you have to declare an explicit rule to set the focus of the session to the particular Agenda. You can use the below rule to set agenda in Stateless Session:

 rule "global"
 salience 100
    when
        $f : IngestFileMetadata()
    then
        drools.setFocus($f.getAgenda());
end

Note : You have to find some way to get the agenda variable in your rule file. In the above example, getAgenda() is a method in your IngestFileMetadata class and it returns agenda value of String type

原来我的问题是一旦我在预检查规则期间更新了属性,就必须对我的事实进行显式更新。那解决了问题。