Book Image

Drools JBoss Rules 5.X Developer's Guide

By : Michal Bali
Book Image

Drools JBoss Rules 5.X Developer's Guide

By: Michal Bali

Overview of this book

<p>Writing business rules has always been a challenging task. Business rules tend to change often leading to a maintenance nightmare. This book shows you various ways to code your business rules using Drools, the open source Business Rules Management System.<br /><br />Drools JBoss Rules 5.X Developer's Guide shows various features of the Drools platform by walking the reader through several real-world examples. Each chapter elaborates on different aspects of the Drools platform. The reader will also learn about the inner workings of Drools and its implementation of the Rete algorithm.<br /><br />The book starts with explaining rule basics, then builds on this information by going through various areas like human readable rules, rules for validation, and stateful rules, using examples from the banking domain. A loan approval process example shows the use of the jBPM module. Parts of a banking fraud detection system are implemented with the Drools Fusion module which is the complex event processing part of Drools. Finally, more technical details are shown detailing the inner workings of Drools, the implementation of the ReteOO algorithm, indexing, node sharing, and partitioning.</p>
Table of Contents (22 chapters)
Drools JBoss Rules 5.X Developer's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Setting Up the Development Environment
Creating Custom Operators
Dependencies of Sample Application
Index

Rule syntax


The following section will provide more details on rule (.drl) syntax. It will form the basis for later examples.

Rule concepts

A rule can contain one or many conditions/patterns. For example:

Account( balance == 200 )
Customer( name == "John" )

Code listing 5: Two rule conditions, one for type Account and one for type Customer

Drools will then try to match every Account object in the session whose balance is equal to 200 with every Customer whose name is equal to John. If we have three Account objects that meet this criteria and two that don't, five Customer objects that meet this criteria and three that don't, it would create (3+2)*(5+3)=40 possible matches; however, only 3*5=15 of them valid. Meaning that a rule with these two conditions will be executed exactly 15 times.

Variables in rules

Rules can declare variables as follows:

$account : Account( $type : type )

Code listing 6: This is a simple condition and matches every Account and creates two variables: $account and $type...