在 drools 5.x 中执行多个规则
我对流口水有点陌生。我的 drl 文件中有 2 条规则,即 DateYYYYMMDD 和 TotalChargesAndTax 。我使用以下语法从我的 main 方法执行 2 条规则。
Command<?> syntacticValidation = new FireAllRulesCommand(
new RuleNameEqualsAgendaFilter("DateYYYYMMDD"));
Command<?> semanticValidation = new FireAllRulesCommand(
new RuleNameEqualsAgendaFilter("TotalChargesAndTax"));
List<Command> commands = new ArrayList<Command>();
commands.add(semanticValidation);
commands.add(syntacticValidation);
session.execute(CommandFactory
.newBatchExecution(commands));
但是,当我运行应用程序时,仅执行 TotalChargesAndTax 规则,而跳过 DateYYYYMMDD 规则。如果我交换 ArayList 中命令对象的位置(如下所示),
commands.add(syntacticValidation);
commands.add(semanticValidation);
则执行 DateYYYYMMDD 规则并跳过 TotalChargesAndTax 规则。有没有办法同时执行这两个规则并执行这两个规则的结果?到目前为止,仅执行一个结果,具体取决于数组列表中第一个命令。
I am a bit new to drools. I have 2 rules namely DateYYYYMMDD and TotalChargesAndTax in my drl file. I am using the following syntax to execute the 2 rules from my main method.
Command<?> syntacticValidation = new FireAllRulesCommand(
new RuleNameEqualsAgendaFilter("DateYYYYMMDD"));
Command<?> semanticValidation = new FireAllRulesCommand(
new RuleNameEqualsAgendaFilter("TotalChargesAndTax"));
List<Command> commands = new ArrayList<Command>();
commands.add(semanticValidation);
commands.add(syntacticValidation);
session.execute(CommandFactory
.newBatchExecution(commands));
But when I run my application, only the TotalChargesAndTax rule is executed and the DateYYYYMMDD rule is skipped. If I interchange the position of the command objects in the ArayList as shown below,
commands.add(syntacticValidation);
commands.add(semanticValidation);
then the DateYYYYMMDD rule is executed and the TotalChargesAndTax rule is skipped. Is there a way to execute both the rules and execute the consequence of both the rules? As of now, only one consequence is executed depending on which command is first in the array list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您编写规则时,您无法确定必须触发哪个规则。规则引擎将根据您在知识会话中插入的事实/pojo 选择规则。我建议您不要使用议程过滤器来尝试强制执行规则。如果您插入的对象与规则条件端 (WHEN) 匹配,则将自动执行多个规则。
如果您想分享您的规则,我们可以为您提供帮助。
干杯
When you write rules you cannot say which rule must fire. Rules will be picked by the rule engine based on the facts/pojos that you insert in your knowledge session. I recommend you to not use Agenda filters to try to force rules execution. Multiple rules will be executed automatically if the objects that you insert match with your rules conditional side (WHEN).
If you want to share how your rules looks like we can help you.
Cheers