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.
Related
I have 2 drools file in the same package com.sample.order.rules
orders.drl and order-summary.drl. I want to process all the orders in orders.drl and then from the results of order.drl processing, create an order summary using order-summary.drl. I currently control the order of execution by setting all the saliences in order-summary.drl to -1. Is it possible to solve this problem any other way? The problem is the number of rules is increasing and adding salience to every rule in order-summary.drl just doesn't feel right.
It is possible to control the execution order of groups of rules with the attribute ruleflow-group, see examples from the docs. In general, the approach is:
Tag your related rules with a ruleflow-group attribute.
Create a BPMN Flow (a Business Process)
Associate each of your ruleflow-groups with a Business Process Task
Trigger your rules under a jBPM Process
This allows you to (optionally) only trigger your Summary steps when some conditions in the previous Orders step have been satisfied. I would suggest looking at the Mortgage_Process example provided by the Drools Business Central Showcase Docker image. To set up the KIE Execution Server API to test your rules and processes iteratively, see the docker-compose set up here.
Step 1
rule "order rule 1"
ruleflow-group "orders"
when
Order ( value > 10 )
then
insert ( new Shipment () );
end
rule "summary rule 1"
ruleflow-group "summary"
when
Shipment ()
then
// do stuff
end
Step 2
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).
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.
How to Fire all the rules in drools regardless of which group it belongs to,
I have two Rule-flow groups i.e., "rules1" "rules2", How to fire all the rules without mentioning rule-flow group name? I want to apply all the rules.
This is not possible. If a rule is in a group, the group has to receive the focus - otherwise the rules won't fire.
However, it isn't difficult at all to add a rule that will set the focus to another group.
Also, you can write a very simple loop setting the focus to group after group and to fire all rules.
If you don't need the grouping, remove the rule attribute.
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!