Giter Site home page Giter Site logo

drools's Introduction

Drools

Table of Content

Overview

  • 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.

      • KieContainer: To work with kie technologies, we have to instantiate a KieContainer.
      • KieSession: We have to get it from the KieContainer to work with drools. This is used to give facts to the rule engine and fire rules.

Installation

  • 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
  • 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


Modules


Appendix

drools's People

Watchers

James Cloos avatar Rahul Kiran Gaddam avatar

Forkers

juhpatel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.