- JBoss Drools is a Business Rule Management System. It is a framework where you can create rules that defines when a specific action should be done.
- It can be used for applications where business rules can be externalized and will be uploaded by business users.
- One of the major drawback of drools is it consumes lots of memory.
- Drools execution workflow is split into two main parts:
- Authoring: Authoring process involves the creation/setup of Rule files.
- Runtime: It is creation of working memory and handling the activation.
- Fundamentals terminologies of drools:
-
Rules: These are part of knowledge that performs some tasks when specific conditions occur. These are defined as
.drl
files.package <org.example.com> import <org.example.class>; global <variable_name>; rule <rule_name> salience <number> <attribute> <value> when <conditions> then <actions>; end
- package keyword is used to acts as a namespace for Rules. Rule names within a package must be unique. These are similar to Java packages
- import keyword is used to import fact/action pojo classes that act as data model/action helpers.
- global keyword is used in drools to define a global variable. Global variable are used to make a variable visible to all the rules inside a DRL file.
- dialect keyword is used in drools to define the syntax employed in the expressions in the condition section or action section. By default the dialect is Java. Drools also support dialect mvel.
- rule keyword must be followed by a logical rule name.
- salience keyword is used by the conflict resolution strategy to decide which rule to fire first. It has one attribute, which takes any expression that returns a number of type int (positive as well as negative numbers are valid). The higher the value, the more likely a rule will be picked up by the conflict resolution strategy to fire.
- when keyword must be followed by some condition.
- then keyword must have the consequence part if the when condition is met.
- Rules actions have below keywords
- modify: Used to modify attributes of facts.
- insert: Used to insert a new fact for the given session.
- retract: Used to remove fact from current session.
-
Knowledge Base: It represents the knowledge in the Drools ecosystem which stores resources that form rules.
-
Data Model: It contains structure of data on which rules are applied. A data model is a set of java classes that define data types.
-
Rule Engine: It is a rule-based approach to implement an knowledge-based systems which can be used to make decisions. It is also refereed as Production Rule System.
-
Facts: It represents the data which serves as input for rules.
-
Inference Engine: This is the brain of Rule Engine. It can scale to number of rules and facts. It matches facts/data against Rules.
-
Pattern Matching: This process matches facts with rules by the Inference Engine. Drools Implements and extends the Rete Algorithm for pattern matching.
-
Working Memory: It is a storage of facts, where they are used for pattern matching. It can be modified, insert, and remove.
-
Knowledge Session: This component holds all the resources required for firing rule. Here, all facts are inserted into the single session, and then matching rules are fired.
-
Module: This is a module which stores multiple Knowledge Bases which can hold different sessions.
-
Agenda: It's a logical concept. The agenda is the logical place where rules are waiting to be fired.
-
Activations: It is the then part of the rules. These are placed in the
agenda
where the appropriate rule are fired. -
KIE: "Knowledge Is Everything" is an umbrella project introduced to bring related technologies.
-
-
Setting Development Environment
- Install VSCode and below plugins
- Java Extension Pack
- Drools
- Check out code from modules
- Navigate to MAVEN PROJECTS and click on package
- Navigate to <Project>->target-><Project>-1.0-SNAPSHOT.jar, Mouse Right-Click and get Copy Relative Path and run
java -jar <relative-path>/<Project>-1.0-SNAPSHOT.jar
- Install VSCode and below plugins
-
Docker Based Installation
- Create a Oracle Linux 7 environment.
- Execute below commands to run Drools Workbench
# Creating base folders cd /scratch mkdir -m777 docker_storage mkdir -m777 wb_git # Adding Proxy Server Details vi ~/.bash_profile export http_proxy="http://<server>:<port>" export https_proxy="http://<server>:<port>" export no_proxy="localhost,127.0.0.1,.<orgextension>.com" # Setting up docker sudo su chmod 777 /var/run/docker.sock systemctl stop docker /usr/sbin/usermod -a -G docker <login user> /usr/sbin/sysctl net.ipv4.conf.all.forwarding=1 vi /etc/docker/daemon.json { "data-root":"/scratch/docker_storage" } systemctl start docker exit # Checking Docker docker run hello-world # Executing Drool Workbench docker run -p 8080:8080 -p 8001:8001 -e JAVA_OPTS="-server -Xms2024m -Xmx2024m -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8" -v /scratch/wb_git:/opt/jboss/wildfly/bin/.niogit:Z -d --name drools-workbench jboss/drools-workbench-showcase:latest # Checking error in executions docker ps docker logs <container_id>
- After successful execution of above script, drool workbench will be available here with user/pwd as
admin/admin
. - To install KIE Execution server using Docker, run below command. This will automatically make kie server enabled in drool workbench.
docker run -p 8180:8080 -d --name kie-server --link drools-workbench:kie-wb jboss/kie-server-showcase:latest
- Below are the example implementations of drools project.