Drools execute one rule for each rule table inside of decision table excel

Viewed 13

I am looking for a solid solution for exit on the first match rule for each rule table inside the decision table excel,

Currently, there are 2 rule tables in excel, it is because one field is updated in the first rule table, and the second rule table uses the updated value,

I try below code, but it only fires one rule at the first rule table, not execute any rule from the second rule table, so it doesn't help,

kieSession.fireAllRules(1);
2 Answers

You're calling fireAllRules(1);. The 1 means you will only fire one rule. If you want to fire 2 rules, you need to either not pass any value and use fireAllRules(), or explicitly call fireAllRules(2). The integer indicates the maximum number of matches (rule hits) allowed -- if you restrict it to 1 you'll only ever have at most a single rule trigger; bumping it to 2 means you'll have 0, 1, or 2 hits.

Now for dealing with "first table" and "second table", that's a design question. One option is to load them as separate KieBases and you can easily just fire them sequentially via distinct sessions. Obviously you'll need to copy the modified data from the first session to the inputs of the second session.

Alternatively, you could use the other built-in groupings mechanisms provided by Drools. @tarilabs in their answer suggested activation-group, which is a fine choice because it only allows a single rule to fire within that group. Stick all of your "first table" rules under one activation group, and all of your "second table" rules under a second, and then fire them in sequence. There's also agenda-groups if you want to be a bit looser on the "one rule only" restriction but still need the different groups to run one at a time.

Related