
Explore the Drools rule engine by learning its purpose, solving problems with a rule-based approach, and mastering Drools syntax through progressively added examples and live code runs.
Explore how a rule engine uses domain experts and declarative rules to evaluate data, fire actions, and iterate until no rules remain, contrasting with imperative flows in visa applications.
We look at the example code I have created in Github: https://github.com/aasaru/drools-training
You need JDK 17 or JDK 19 to run this code.
Learn to check out and run the Drools example code with IntelliJ IDEA Community Edition by cloning from GitHub, importing as a Maven project, and configuring Java 8.
NB! After filming this part newer Drools version has been released and I have updated the source code. Please open pom.xml and find out the correct version.
Differences between stateful and stateless use cases. For which use cases to use Drools stateless sessions.
Split a single multi-purpose Drools rule into two focused rules, one matching expired passports and another matching passports with zero unused visa pages, and compare the changes in step two.
Bind a variable in step three of stateless Drools sessions to show passport ownership. Print the owner and visa status using pattern binding and getters like getName and getUnusedVisaPages.
Rewrite the rule to avoid repetition in steps five and six, treating passports without validation info as okay while rules mark invalid ones, and note stateless sessions can't reflect changes.
Explore stateless sessions and use cases—validation, calculation, routing, and filtering—and how to declare statelessness in XML, while keeping rules short, using dollar-prefixed variables, and noting that state changes aren’t propagated.
Explore how Drools rules join passports with visa applications to validate entries, using a stateful session to insert visa applications and modify objects to reflect validation results.
In step two of Drools programming, learn to enforce passport validity six months after visit end by adding a cross-product rule that flags visa applications and marks validation failed.
Add new facts with Drools, issue visas when validation passes, and learn to control rule execution order using salience or agenda groups.
You can write Drools rules in either "java" or in "mvel" dialect.
Here I explain the difference of them and why I changed section06 code to use "java" dialect.
Learn to control drools execution with agenda groups instead of salience, organizing rules into invalid passport, valid passport, invalid application, and valid application groups, using a stack and debug listener.
Use three agenda groups: validate passport, validate application, and issuing visa, and apply salience within the groups to prioritize failed validations over passes.
In this self-assignment you learn how to set focus to agenda group in the rules.
I have added this assignment after publishing the course. You may need to run "git pull" to get the latest code. It comes without a video and you must examine the rules and Java code yourself.
demonstrates insert logical in drools by inserting visas, tracking updates and deletions with event listeners; shows how changing the when clause can delete previously inserted facts and invalidate visa applications.
Eliminate positive cases by focusing on negative ones, rewrite the visa rule with red stickers, and automatically remove invalid visas, reducing the rule set to four.
Design Drools rules with fact objects, manage session facts, and track insertions, updates, and removals using event listeners for debugging, ensuring extensible, well-structured rule logic.
Rewrite a complex drools rule to a single for all expression, ensuring the group leader and all members are under 18, then confirm all are at least ten.
Learn to work with groups of facts in Drools, using exist to confirm at least one fact and for all to validate expressions or find the lowest or highest value.
Learn how spreadsheet decision tables convert independent conditions into drools rules. Use a family visa fee example to map urgent and person count to a DRL action.
Starting this section the code examples are taken from another Git repository. In this lecture, I will give an overview of how this repository differs from the previous one.
Open the spreadsheet decision table, view the three conditional columns and one action, then convert it to a drl file to drive rule execution that prints fees 300, 100, 140.
Define multiple action columns in a spreadsheet to link visa applications with fees, add a visa fee domain object and insert action, and retrieve results from the rule session.
Set a custom drl rule name and add a comment by using the name and description columns in the rule table, showing how rules are generated from rows.
Demonstrates how to use Drools with multiple rule tables in a spreadsheet to generate visa fees from passport data, with parameter substitution, and notes that the first sheet is used.
Join multiple fact objects in a spreadsheet decision table by linking passport and visa application with the passport number to calculate the urgent fee in a Drools rules session.
Sequential true in rule sets adds unique salience to each rule, overriding the priority column, and demonstrates using a sequential max priority to control firing order.
Explore activation groups in spreadsheet decision tables and how they limit rule firing. See how join columns, params, and variables merge data, with salience guiding sequential execution.
Declare an intermediate type in DRL to model a risk factor with visa application id and risk, insert it, and count risk factors to decide a visa verdict.
Declare and use enumerations in Drools DRL, read back risk factor objects as enums, and handle intermediate facts with Java integration for debugging and JSON conversion.
We learn Apache Drools DSL (Drools programming language) and go over the most common DSL constructs. We move in small steps and gradually introduce new concepts, so it is easier to follow even for a beginner.
This way we cover the most common Drools topics like:
what is a rule engine
what is the difference between a method and a rule
why one would use a rule engine instead of writing regular Java code
understanding of the when/then clauses
understanding in which order the rules fire and when the order is not known
how to control the execution using activation groups, agenda groups and salience
declaring variables in DRL
difference between stateless and stateful sessions
inserting facts and modifying existing objects in the session
cross products (similar to SQL join)
exists, forall and collect
using spreadsheet decision tables to create Drools rules
using templates for creating rules and feeding data into them from spreadsheets and other tabular data sources
complex event processing (CEP) in Drools
difference between fact and event
declaring facts and events in Java and inside DRL code
different rule execution modes (active/passive, cloud/stream, sequential)
time and length-based sliding windows
entry-points
global variables
timers
how Apache Drools' internal algorithm Phreak works
This course comes with two Java projects containing all the code we worked with during the course. The first project includes all the code examples in traditional Drools syntax and a second copy of all the rules in the new Drools OOPath syntax (introduced by Drools 8). The first project has been upgraded to run using Drools 10.
You are encouraged to check out and run the code yourself to better understand and experiment with changes.
There are instructions on running the code in IntelliJ, Eclipse, and VS Code.
After completing this course, you will better understand which kinds of problems could be solved with Drools and how to write the most common business rules in Drools DSL.