Drools Plugin

Drools Plugin 

Drools is a business rule management system (BRMS) and an enhanced Rules Engine implementation, ReteOO, based on Charles Forgy's Rete algorithm tailored for the Java language.

Author: Manohar Viswanathan (manohar.viswanathan@gmail.com)

Features

  • Easy implementation of Drools
  • Rules can be stored in file or in database
  • Rules can be dynamically changed without rebuilding or restarting application

Installation

grails install-plugin drools

Usage

Components

  • DroolsController: Provides CRUD functionality for Drools Rule
  • DroolsService: Fires all rules

DroolsService

droolsService.fireRules(resource, ruleKey, objList)

  • resource: specifies where the rules are stored. 'file' or 'db'
  • ruleKey: identifier for the rule. For 'file' resource, this would be the name of the file (eg:ticket_example.drl). For 'db' resource, this is the Drools Rule key
  • objList: list of objects that need to be put in session

Example

A simple Ticket processing system is available in the plugin. This example shows how tickets are processed based on their subscription plan.

Run the example: http://localhost:8080/your_app/drools/example

Your console output should be:

Start processing Ticket # 3
Start processing Ticket # 2
Start processing Ticket # 1
Firing rule Bronze Priority for Ticket # 3
Firing rule Silver Priority for Ticket # 2
Firing rule Gold Priority for Ticket # 1
Firing rule Special Discount for Ticket # 1

Display on your browser should be:

Tickets due for processing:
Ticket #1: CustomerName:Jack, Subscription:Gold, Discount:0% Status:New
Ticket #2: CustomerName:Tom, Subscription:Silver, Discount:0% Status:New
Ticket #3: CustomerName:Bill, Subscription:Bronze, Discount:0% Status:New
Firing rules now ...
Tickets after processing:
Ticket #1: CustomerName:Jack, Subscription:Gold, Discount:5% Status:Escalate
Ticket #2: CustomerName:Tom, Subscription:Silver, Discount:0% Status:Escalate
Ticket #3: CustomerName:Bill, Subscription:Bronze, Discount:0% Status:Pending
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.