Drools JBoss Rules 5.0 Developer's Guide

Drools JBoss Rules 5.0 Developer's Guide
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 25%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Discover the power of Drools as a platform for developing business rules
  • Build a custom engine to provide real-time capability and reduce the complexity in implementing rules
  • Explore Drools modules such as Drools Expert, Drools Fusion, and Drools Flow, which adds event processing capabilities to the platform
  • Execute intelligent business logic with ease using JBoss/Drools, a stronger business-rules solution
  • Covers examples of a fraud detection system utilizing Drools CEP (Complex Event Processing) capabilities

Book Details

Language : English
Paperback : 320 pages [ 235mm x 191mm ]
Release Date : July 2009
ISBN : 1847195644
ISBN 13 : 9781847195647
Author(s) : Michal Bali
Topics and Technologies : All Books, Enterprise Products and Platforms, Java, JBoss, Open Source


Table of Contents

Chapter 1: Introduction
Chapter 2: Basic Rules
Chapter 3: Validation
Chapter 4: Data Transformation
Chapter 5: Human-readable Rules
Chapter 6: Stateful Session
Chapter 7: Complex Event Processing
Chapter 8: Drools Flow
Chapter 9: Sample Application
Chapter 10: Testing
Chapter 11: Integration
Chapter 12: Performance
Appendix A: Development Environment Setup
Appendix B: Custom Operator
Appendix C: Dependencies of Sample Application
  • Chapter 1: Introduction
    • Problems with traditional approaches
    • The solution
      • Advantages
      • Disadvantages
        • When not to use a rule engine
    • Drools
    • Alternatives to Drools
    • Summary
  • Chapter 2: Basic Rules
    • Rule basics
      • Executing rules
    • Rule syntax
      • Rule concepts
        • Variables in rules
        • Types
        • Comments
      • Package
        • Imports
        • Global variables
        • Functions
        • Dialect
      • Rule condition
        • And
        • Or
        • Not
        • Exists
        • Eval
        • Return value restriction
        • Inline eval
        • This
        • Working with collections
      • Rule consequence
      • Rule attributes
        • salience (priority)
        • No-loop
        • Dialect
    • Summary
  • Chapter 3: Validation
    • Banking domain model
    • Problem definition
    • Analysis
    • Design
    • Validation package
      • Object required type rules
      • Testing
      • Minimal account balance rule
      • Student account rule
      • Unique account number rule
    • Implementation
    • Validation service
    • Summary
  • Chapter 4: Data Transformation
    • Process overview
    • Getting the data
      • Loading facts into the knowledge session
    • Writing transformation rules
      • Testing
      • Address normalization
      • Testing the findAddress rule
      • Unknown country
      • Currency conversion
      • One account allowed
    • Transformation results
    • Implementation of the data loading
      • Database setup
      • Project setup
      • iBatis configuration
      • Running iBatis
      • Alternative data loading
    • Summary
  • Chapter 5: Human-readable Rules
    • Domain Specific Language
      • DSL as an interface
      • DSL for validation rules
      • File formats
        • DSL file format
        • DRL file format
        • DSLR file format
      • DSL for multiple constraints in a condition
      • Named capture groups
      • DSL for data transformation rules
    • Decision tables
      • Advantages of a decision table
      • Disadvantages of a decision table
      • Calculating the interest rate
        • Project setup
        • Testing
        • Comma Separated values
      • Rule Templates
    • Drools Flow
      • Drools Agenda
      • Methods for managing rule execution order
      • Ruleflow
        • Start
        • End
        • Action
        • RuleFlowGroup
        • Split
        • Join
      • Example
      • Rules
      • KnowledgeBase setup
      • Tests
    • Summary
  • Chapter 6: Stateful Session
    • Introduction to stateful session
    • Validation using stateful session
      • Design overview
      • Stateful validation service
      • Integration testing
      • Logical assertions
      • Keeping the validation report up-to-date
        • Collect conditional element
      • Serialization
        • Knowledge session re-creation
        • Testing
        • Session serialization
        • Full session serialization
    • Summary
  • Chapter 7: Complex Event Processing
    • CEP and ESP
    • Drools Fusion
    • Fraud detection
      • Problem description
      • Design and modeling
      • Fraud detection rules
        • Notification
        • Monitoring—averageBalanceQuery
        • Two large withdrawals
        • Sequence of increasing withdrawals
        • High activity
    • Summary
  • Chapter 8: Drools Flow
    • Loan approval service
      • Model
    • Loan approval ruleflow
      • Invalid loan application form
        • Email work item
        • Fault node
      • The size of the loan
        • Test for a small loan
      • Rating Calculation
        • Subflow
        • Subflow diagram
        • Rating calculation subflow test
      • Decisions on rating
        • Testing the 'Rating?' node
      • Transfer Funds work item
        • Work item definition
        • Work item registration
        • Work item handler
        • Work item handler registration
        • Testing the transfer work item
      • Human task
        • Test for the human task
      • Final Approval
        • Test for the 'Approve Event' node
      • Banking service
      • Disadvantages of a ruleflow
    • Summary
  • Chapter 9: Sample Application
    • Users
    • Architecture
    • Technologies used
      • Additional Drools projects used
        • Libraries used
    • Business logic
    • Design
    • Configuration
      • JPA annotations for domain objects
      • JPA configuration
      • Spring Framework configuration
      • Web application setup
        • Tag library
      • Tomcat setup
      • Deployment
    • Repositories
    • Validation
      • Services
      • Transactions
      • Presentation layer
        • Localized messages
        • Customer save form controller
      • Complex Event Processing service
    • Loan approval
      • Loan request form
      • Process persistence
      • Task list
      • Working on a task
      • Loan approval event
    • Summary
  • Chapter 10: Testing
    • How to write unit tests for rules
    • Rule integration testing
    • Rule acceptance testing
      • Creating a test scenario
      • Running a test scenario
      • Running all test scenarios
    • Static analysis of rules
    • Troubleshooting techniques
      • Event listeners
      • Debugging
      • Source of generated classes
      • mvel tricks
  • Summary
  • Chapter 11: Integration
    • Dynamic KnowledgeBase loading
      • KnowledgeAgent
    • External artifact building
      • Building with Ant
    • Drools execution server
      • Interest rate calculation example
        • The server
        • The client
    • Spring Framework integration
      • KnowledgeBaseFactoryBean
    • Standards
      • JSR94 Java Rule Engine API
    • Summary
  • Chapter 12: Performance
    • Rete algorithm
      • Node types
        • Rete node
        • EntryPointNode
        • ObjectTypeNode
        • AlphaNode
        • LeftInputAdapterNode
        • TerminalNode
        • BetaNode
        • More complex example
        • EvalNode and FromNode
      • Retracting or modifying a fact
      • Initial fact
    • Node sharing
      • Example
    • Node indexing
      • AlphaNode indexing
        • Computation complexity
      • BetaNode indexing
        • Example
    • KnowledgeBase partitioning
      • Parallel execution
    • Summary

Michal Bali

Michal Bali, freelance software developer, has more than 8 years of experience working with Drools and has an extensive knowledge of Java, JEE. He designed and implemented several systems for a major dental insurance company. He is an active member of the Drools community and can be contacted at michalbali@gmail.com.

Code Downloads

Download the code and support files for this book.

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 7 submitted: last submission 31 Jul 2013

Errata type: Typo | Page number: 11

you could simply reuse the validation rules in you batch import application) Should be changed to: you could simply reuse the validation rules in your batch import application).


Errata type: Typo | Page number: 302

Therefore by purchasing Drupal 6 Site Builder Solutions, Packt will have given some of the money received to the Drools project. Should be changed to: Therefore by purchasing Drools JBoss Rules 5.0 Developer's Guide, Packt will have given some of the money received to the Drools project.


Errata type: Code | Page number: 264

rule noCustomerWithLowAccountBalance when $address : Address( addressLine1 == "Rossa Avenue" ) not ( $account : Account( balance < 100 ) and Customer( accounts contains $account ) ) then System.out.println("No customers with low balance in "+ "their accounts live at Rossa Avenue"); end Should be changed to: rule noCustomerWithLowAccountBalance when $address : Address( addressLine1 == "Rossa Avenue" ) not ( $account : Account( balance < 100 ) and Customer( accounts contains $account, address == $address ) ) then System.out.println("No customers with low balance in "+ "their accounts live in Rossa Avenue"); end


Errata type: Typo | Page number: 11

We'll find out that the possible solutions will wary greatly. Should be changed to: We'll find out that the possible solutions will vary greatly.


Errata type: Typo | Page number: 32

In the section: (Not) memberOf In the first paragraph it states: "Conditions in code listing 33 can be rewritten as:" should be "Conditions in code listing 34 can be rewritten as:"


Errata type: Code | Page number: 31

Section: Testing object identities/equalities Code listing 30: Comparing two Customer instances using Customer method $customer1 : Customer() $customer2 : Customer( eval ( customer$2 != $customer1 ) ) should be (?): $customer2 : Customer( eval ( $customer2 != $customer1 ) )


Errata type: Code | Page number: 62

$addressMap["_type_"] = "Address" causes a runtime error for me.So change it to $addressMap.put("_type_","Address") to get it to work.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Drools JBoss Rules 5.0 Developer's Guide +    EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g =
50% Off
the second eBook
Price for both: €34.10

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Write more efficient business rules, and work with the Rete algorithm, node indexing, node sharing, and parallelization
  • Create a WS-HumanTask-compliant WorkItem in a process (workflow)
  • Implement concurrency control in cross-cutting functionalities to manage code easily
  • Write human-readable rules, and Domain Specific Language for your rules to easily understand and verify them
  • Generate a stateful service by using a stateful knowledge session that maintains state between invocations and teaches you how to transactionally persist this service
  • Develop dynamic remote knowledge-base loading to change rules in your application without even stopping it
  • Prepare decision tables for calculating account interest rates
  • Integrate Drools within your Java business application, and integrate it with the Spring framework

In Detail

Business rules can help your business by providing a level of agility and flexibility. As a developer, you will be largely responsible for implementing these business rules effectively, but implementing them systematically can often be difficult due to their complexity. Drools, or JBoss Rules, makes the process of implementing these rules quicker and handles the complexity, making your life a lot easier!

This book guides you through all of the features of Drools, such as dynamic rules, the event model, and Rete implementation with high performance indexing. It will help you to set up the JBoss Rules platform and start creating your own business. It's easy to start developing with Drools if you follow its real-world examples that are intended to make your life easier.

Starting with an introduction to the basic syntax that is essential for writing rules, the book will guide you through validation and human-readable rules that define, maintain, and support your business agility. As a developer, you will be expected to represent policies, procedures and. constraints regarding how an enterprise conducts its business; this book makes it easier by showing you it can be done.

A real-life example of a banking domain allows you to see how the internal workings of the rules engine operate. A loan approval process example shows the use of the Drools Flow module. Parts of a banking fraud detection system are implemented with Drools Fusion module, which is the Complex Event Processing part of Drools. This in turn, will help developers to work on preventing fraudulent users from accessing systems in an illegal way.

Finally, more technical details are shown on the inner workings of Drools, the implementation of the ReteOO algorithm, indexing, node sharing, and partitioning.

A developer's guide to the powerful Java business rules platform.


This is a problem-solution guide that starts with an introduction to a problem and continues with a discussion of the possible solution. The book covers best practices when working with Drools. The examples and their solutions are accompanied by plenty of code listings and figures providing a better view of the problem.

Who this book is for

The book is for Java developers who want to create rules-based business logic using the Drools platform. Basic knowledge of Java is essential.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software