我如何定义在 EasyRules 中只能执行一个规则?

How can I define that only one rule has to be executed in EasyRules?

我正在使用 easy-rules 来评估一组场景,每个场景都会执行不同的逻辑。我想确保从所有注册的规则中只执行一个,我有以下代码:

public static void main(String[] args) {
    Facts facts = new Facts();
    facts.put("object", "value");

     Rules rules = new Rules();
     rules.register(new Rule1());
     rules.register(new Rule2());
     rules.register(new Rule3());

     RulesEngine rulesEngine=new DefaultRulesEngine();
     rulesEngine.fire(rules, facts);
}

在前面的示例中,我想确保如果 Rule1 被执行,则 Rule2 和 Rule3 不会被执行。

感谢您的帮助

要在匹配发生后停止进一步执行规则,您需要按如下方式配置规则引擎:

RulesEngineParameters parameters = new RulesEngineParameters()
.skipOnFirstAppliedRule(true);
RulesEngine rulesEngine=new DefaultRulesEngine(parameters);

From the Docs :