Drools Tutorials- Understanding Execution Control in Drools using Simple Example
Overview
In previous chapter we implemented a drools project to understand various attributes like salience. In this tutorial we will try to understand the execution controls statements in Drools agenda-group, ruleflow-group and activation-group.If your KieBase defines multiple rules and if you want to selectively execute a subset of them, Drools provides several features to accomplish that.
- agenda-group:This is an optional keyword. It can be assigned for all rules. If not assigned to any agenda group, the rule by default belongs to main agenda.
- ruleflow-group: This behaves exactly similar to agenda-group, except that it is generally used for rules used from jBPM process flows.
- activation-group is a reserved keyword in drools drl file. There can be a single rule or multiple rules that can belong to a particular activation-group. Rules that belong to activation-group fire in similar fashion to "if..else if..else" block in java. In an activation group only one rule can fire at a time
JBoss Drools - Table of Contents
JBoss Drools Hello World JBoss Drools Hello World-Stateful Knowledge Session using KieSession JBoss Drools- Understanding Drools Decision Table using Simple Example Understand Drools Stateful vs Stateless Knowledge Session Drools Tutorials- Backward Chaining simple example Drools Tutorials- Understanding attributes salience, update statement and no-loop using Simple Example Drools Tutorials- Understanding Execution Control in Drools using Simple Example Drools Tutorials- Integration with Spring MVC Drools Tutorials- Integration with Spring Boot
Video
This tutorial is explained in the below Youtube Video.Lets Begin
Understanding activation-group
For our example here we will use the example of jewellery shop we used before. We will be modifying the files as follows-In the drl file we add the salience attribute and activation-group.
package com.rule
import com.javainuse.model.Product
rule "Offer for Diamond"
when
productObject: Product(type=="diamond")
then
productObject.setDiscount(15);
end
rule "Offer for Gold"
salience 1
activation-group "gold"
when
productObject: Product(type=="gold")
then
productObject.setDiscount(productObject.getDiscount() + 5);
System.out.println("Offer for Gold");
end
rule "Offer for Gold on Festival"
salience 2
activation-group "gold"
when
productObject: Product(type=="gold") && Product(event=="sale")
then
productObject.setDiscount(productObject.getDiscount() + 5);
System.out.println("Offer for Gold on Festival");
end

Download Source Code
Download it - Drools execution control exampleJBoss Drools Hello World JBoss Drools Hello World-Stateful Knowledge Session using KieSession JBoss Drools- Understanding Drools Decision Table using Simple Example Understand Drools Stateful vs Stateless Knowledge Session Drools Tutorials- Backward Chaining simple example Drools Tutorials- Understanding attributes salience, update statement and no-loop using Simple Example Drools Tutorials- Integration with Spring Drools Interview Questions Drools-Main Menu.
Popular Posts
1Z0-830 Java SE 21 Developer Certification
Azure AI Foundry Hello World
Azure AI Agent Hello World
Foundry vs Hub Projects
Build Agents with SDK
Bing Web Search Agent
Function Calling Agent
Spring Boot + Azure Key Vault Hello World Example
Spring Boot + Elasticsearch + Azure Key Vault Example
Spring Boot Azure AD (Entra ID) OAuth 2.0 Authentication
Deploy Spring Boot App to Azure App Service
Secure Azure App Service using Azure API Management
Deploy Spring Boot JAR to Azure App Service
Deploy Spring Boot + MySQL to Azure App Service
Spring Boot + Azure Managed Identity Example
Secure Spring Boot Azure Web App with Managed Identity + App Registration
Elasticsearch 8 Security - Integrate Azure AD OIDC