I have written a Drool rule as shown below:
rule "first and second"
activation-group "first"
activation-group "second"
when
// conditions
then
// actions
end
However, when compiling, I get this error:
Duplicate attribute definition: activation-group in rule first and second
I want to know if it is possible to include multiple activation-groups in a rule. If this is possible, how can you do it?
Thanks in advance.
It's not possible to use multiple activation groups in a single rule. If you feel the need to do this then you should restructure your rules to be a little smarter with your conditions so you can get it to a state that would work with single activation groups (per rule).
Related
I am building a rule Engine in which I want to group rules in such a way that for a particular fact drools will not check for all the rules instead it will check for the rule in a specific group.
Is it possible to implement?
Yes. It is possible to implement, you have to implement a process with the rules you want to apply to the specific group, then you can implement a rule like this:
rule "start process if ..."
when
// Fact in specific group?
then
kcontext.getKieRuntime().startProcess("ProcessName");
end
I would recommend you to follow the official drools tutorial, specially the lesson 4: https://nheron.gitbooks.io/droolsonboarding/content/gettingStarted/lesson_4__ruleflow.html
They teach you how to do this step by step.
I have some rules and rule flows. I have scenario that I should assign more than one ruleflow-group to a rule. I m in a situation where I cant assign a common rule flow group name. When I gave two rule flow group name like ruleflow-group "group1" "group2" it throws error. Is it possible to have something like this above ?
Multiple ruleflow-group on a single rule is not supported and there is no plan to be supported.
For reusable perspective, I have one Rule with Rule Flow group. I have use same rule flow group multiple times in flow. Now the situation is its should be fire same rule more then one time,but its only fire that rule single time.
I don't understand why its happens.
Can you give me an idea why its happening and whats the solution for same?
A Rule Task in a flow does not "execute" the rules in a rule-flow-group, it merely activates that group in the agenda so IF there are active rules, they will fire.
If between 2 executions of your Rule Task you modify the session in a way that new activations are created, consecutive executions of your task should fire new activations of those rules.
Hope it helps,
I need to execute some rule as the last rule. Any one knows how to do this ?
Also can a rule change behavior of other rules ? For example can a rule be used to execute certain rule package ?
Thanks in Advance.
yes you can use the rule attribute salience to give your rules priority.
You can insert a fact in the Right Hand Side of the rule to make another rules match.
You can also read the documentation for Agenda Groups to select different groups of rules that will be executed at different times.
Hope it helps!
I defined multiples rules in one DRL file, how to set order, want to execute one after another (top to bottom).
Rules are fired automatically when the conditions are met when the inserted facts(objects) are updated. But if in case you want to run it from top to bottom, you can set a property called salience in the rule. The value it takes is an integer. The rule with the highest salience is executed first.
rule "First name mandatory"
salience 10
when
(Person(firstName=="" || firstName==null))
then
...
end
If you use salience you will be killing the rule engine, because you will be forcing the rule execution order instead of letting the engine decide.
Cheers
Setting priority to rules is the best form.
Use Salience to determine the priority of each rule, where a higher number denotes a higher priority.
The default Salience for rules is 0, and you can give negative Salience, for example,if you want a rule to be fired last.