简体   繁体   English

议程小组在Drools中无法正常工作

[英]Agenda groups not working as expected in Drools

Right now, in my drools project I have two groups of rules in separate DRL files which are split by agenda groups. 现在,在我的流口水项目中,我在单独的DRL文件中有两组规则,这些规则由议程组划分。 For the agenda group "preCheck" I am setting auto focus to true for each rule in that agenda group. 对于议程组“ preCheck”,我将该议程组中的每个规则的自动焦点设置为true。 Example: 例:

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

For the other agenda group - "defaultRules" - the rules do NOT have the auto focus attribute set. 对于另一个议程组-“ defaultRules”-规则未设置自动聚焦属性。 Example: 例:

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

When invoking the rules via the rest API, I am also trying to set focus to the "preCheck" agenda group through the JSON payload. 通过rest API调用规则时,我还尝试通过JSON有效负载将焦点设置为“ preCheck”议程组。 Example: 例:

{
  "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"}
    }
  ]
}

However, when the rules are executed, it seems like the rules in the "defaultRules" agenda group are being evaluated first. 但是,执行规则时,似乎首先评估了“ defaultRules”议程组中的规则。 I have no idea why. 我不知道为什么。 I'm relatively new to drools so it's entirely possible I'm not correctly understanding the concept of agenda groups, but I was sure this design would ensure the "preCheck" rules would evaluate first. 我对流口水还比较陌生,因此很可能我没有正确理解议程组的概念,但是我确信这种设计将确保“ preCheck”规则将首先得到评估。

Can anyone provide any insight on why this is not happening? 谁能提供任何关于为什么不发生这种情况的见解? If I need to provide more details I can. 如果需要提供更多详细信息,我可以。

Thanks in advance. 提前致谢。

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. 在首先讨论如何使用议程组之前,我想说的是,配置议程组取决于您在规则引擎中使用的KieSession类型。 For stateful Session, you can directly configure it by calling ksession.getAgenda().getAgendaGroup( "preCheck" ).setFocus(); 对于有状态会话,您可以通过调用ksession.getAgenda().getAgendaGroup( "preCheck" ).setFocus();直接配置它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 . 对于无状态会话,您必须声明一个明确的规则以将会话焦点设置为特定的Agenda You can use the below rule to set agenda in Stateless Session : 您可以使用以下规则在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 在上面的示例中,getAgenda()是IngestFileMetadata类中的方法,它返回String类型的议程值。

Turns out my issue was having to issue an explicit update to my fact once I updated the attributes during my pre-check rule. 事实证明,一旦我在预检查规则中更新了属性,就必须对事实进行显式更新。 That solved the problem. 那解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM