Drools Plugin

  • Tags : rules engine
  • Latest : 0.3
  • Last Updated: 24 July 2009
  • Grails version : 1.1.1 > *
  • Authors : null
0 vote
Dependency :
compile ":drools:0.3"

Documentation

Summary

Description

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
  • Both java & groovy objects can be passed to Rules Engine. (Note that groovy domain objects must be in a package)

Installation

First create a grails project:  grails create-app XXX
make XXX the current directory

(if you need an http proxy issue: grails set-proxy)

grails install-plugin drools

grails run-app

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