Drools Plugin for Grails Application
I have just released a Grails Plugin for Drools. The plugin details can also be found at http://www.grails.org/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.
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
- Install the plugin
- Verify example rules:
http://localhost:8080/your_app/drools/example - Create your own rules: http://localhost:8080/your_app/drools and use droolsService in your code
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: Customer[Name:Jack, Subscription:Gold, Discount:0%] Status[New] Ticket #2: Customer[Name:Tom, Subscription:Silver, Discount:0%] Status[New] Ticket #3: Customer[Name:Bill, Subscription:Bronze, Discount:0%] Status[New] Firing rules now ... Tickets after processing: Ticket #1: Customer[Name:Jack, Subscription:Gold, Discount:5%] Status[Escalate] Ticket #2: Customer[Name:Tom, Subscription:Silver, Discount:0%] Status[Escalate] Ticket #3: Customer[Name:Bill, Subscription:Bronze, Discount:0%] Status[Pending]
Tags: drools, grails plugins, rules engine