admin管理员组

文章数量:1297058

I have a project in Drools 7.0.0 I have been tasked to print the execution of the rules in the order that it has been executed regardless if the payload has passed or not. Is this possible to iterate through the rules as it is executed for StatelessKie Session?

rule "My First Rule"
when
    Conditions for first rule
    Not routed yet
then
    Route to "First".
end

rule "My Second Rule"
when
    Conditions for second rule
    Not routed yet
then
    Route to "Second".
end

rule "My Third Rule"
when
    Conditions for third rule
    Not routed yet
then
    Route to "Third".
end

So for example, I have a payload that does not pass the first and second rule but it passes the third rule. I want to print the order the rules are executed before it even encounters the third rule and when it encounters the third rule.

First -> Second -> Third, Second -> First -> Third, etc..

I know the answer is it will be arbitrary but I need to prove that it is to confirm. Thanks!

I have a project in Drools 7.0.0 I have been tasked to print the execution of the rules in the order that it has been executed regardless if the payload has passed or not. Is this possible to iterate through the rules as it is executed for StatelessKie Session?

rule "My First Rule"
when
    Conditions for first rule
    Not routed yet
then
    Route to "First".
end

rule "My Second Rule"
when
    Conditions for second rule
    Not routed yet
then
    Route to "Second".
end

rule "My Third Rule"
when
    Conditions for third rule
    Not routed yet
then
    Route to "Third".
end

So for example, I have a payload that does not pass the first and second rule but it passes the third rule. I want to print the order the rules are executed before it even encounters the third rule and when it encounters the third rule.

First -> Second -> Third, Second -> First -> Third, etc..

I know the answer is it will be arbitrary but I need to prove that it is to confirm. Thanks!

Share Improve this question edited Feb 11 at 19:01 Betty Ong asked Feb 11 at 19:00 Betty OngBetty Ong 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

In ReteOO/Phreak, the rules are not "evaluated in order" in the typical sense, as rules will be activated and placed into agenda if matching, and rule firing order for those in the agenda depending on salience and other policies.

What you can do is use AgendaEventListener to check which rules have fired, and in which order, for a fireAllRules/fireUntilHalt "evaluation".

More precisely you can use it to see which Rules matches (so placed into the Agenda), which one is Fired, and which matches are taken off of the Agenda because of side-effects/Modify of the Facts by the rule which just fired.

本文标签: Rules Order of Execution for Stateless KieSessionDroolsStack Overflow