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<Com开发者_Python百科mand> 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.
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
精彩评论