1 of 22

Business Rules with JBoss Drools

Jeff davis

Linked-in

Google +

2 of 22

Agenda

  • Introduction to Business Rules
    • What are Business Rules?
    • What is a Business Rule Management System (BRMS)
    • Benefits to a BRMS
  • Understanding a Rules Engine
    • Facts, Rule Bases and Repository
    • Syntax of a Business Rule
  • Using a BRMS at Your Enterprise
    • Use Cases & Benefits
  • Selecting a Rules Engine
  • Roadmap/Next Steps

3 of 22

What is a Business Rule?

“A statement that defines or constrains some aspect of the business which is intended to assert business structure or to control or influence the behavior or the business” (Business Rules Group)

“Business rules or business rulesets describe the operations, definitions and constraints that apply to an organization in achieving its goals.” (Wikipedia)

“A formal and implementable expression of some user requirement”

“The practices, processes, and policies by which an organization conducts its business”

  • Definitions and Inferences
  • Computations
  • Constraints
  • Instructions
  • Presentation
  • Process

Types of Rules

4 of 22

What is a Business Rules Engine?

Rule Builder/Editor

(Tools for developing and debugging rules)

Rule Deployment and Configuration (Tools for deploying and managing rules)

Rules Engine

Rules Engine

Rules Engine

Business

System

Business

System

Business

System

Shared�Rules

Repository

5 of 22

Traditional Approach to Business Rules

The traditional (ad hoc) approach of dealing with rule changes leads to…

  • Reduced organizational agility
  • Reduced employee productivity
  • Increased load on IT

Issues

  • Rules are hidden in code or isolated within the organization
  • Changes are hard to track and maintain over time
  • Rules used by systems have to be programmed and require IT resources
  • Duplication and multiple versions of the same rules
  • Lack of auditability, traceability
  • Decision changes cannot be easily tested or simulated

Where Business Rules Typically Exist

Applications

Processes

People

Documents

6 of 22

Moving to a BRMS

Where Business Rules Typically Exist

Applications

Processes

People

Documents

Business Rule Management System

Rules are Defined, Analyzed and Maintained

User Tools

Rules are Stored and Shared

Rule Repository

Rules are Deployed, Executed and Monitored

Rule Server

  • Eliminate decision silos
  • Make decision logic accessible to Business and IT
  • Implement fine-grained, context-specific logic

7 of 22

Benefits of the Business Rule Approach

  • Reduce time and resources required to deploy changes
  • Author and maintain rules using non-technical language
  • Express decision logic with increased precision
  • Make decisions based on specific context
  • Increase decision automation
  • Improve visibility and understanding of how decisions control systems
  • Lower maintenance costs; respond quickly to change
  • Business experts can manage and validate decision logic
  • Increase profitability of product, pricing and promotional offerings
  • Customize decisions when possible, standardize if needed
  • Improve process efficiency
  • Ensure compliance; enable sharing/re-use of decision logic

What does it enable?

What is the value?

BRMS

8 of 22

Syntax of a Business Rule

  • Declarative
  • Expressed in Natural Language
  • Follow an If-Then Syntax
  • Atomic – a Single Rule is Either True or False
  • Examples:
    • If an insurance claim exceeds $1200, require a review by an manager.
    • If a vacation request exceeds amount of available hours, reject.
    • If an order exceeds $75, provide free shipping.
    • If customer is new, send out welcome email message with discount coupons.

9 of 22

Rule Engine Basics

  • Rule-Based Systems consist of a rule base, a set of facts, and an inference engine.

Set of Facts (Working Memory /DB)

THEN [Claim] is Approved

IF [Diagnosis] is Covered && [Claim.Cost] < $250

THEN [Claim] is Approved

IF [Customer] is Preferred && [Order.Cost] < $250

THEN [Order] is Approved

Rule-Base

Acme places Order 101 for $175

Acme is a preferred Customer

Inference

Engine

Acme Order 101 is Approved

Result:

10 of 22

Types of Facts

There two general types of facts:

  • Volatile – Represent the instance data that will trigger the rules engine to fire. For example, data submitted for validation during an ESP claim process.
  • Non-Volatile – Generally historically or rather static data. For example, vendor and contract related data.

In most cases, a database will likely be the source for the non-volatile facts, whereas a transaction application will be providing the volatile data that requires processing.

11 of 22

Relationship between Services

This illustration depicts the relationship between the rules engine, exposed as a “decision service”, and the BRMS.

The BRMS is the interface by which the rules can be managed and maintained.

12 of 22

Use Cases for Rules Engine

  • Most likely, you work in rules-based enterprise. Examples:
    • Determine whether a claim is covered by the terms of a contract.
    • Determine the sequence of steps required for processing a new order.
    • Determine the invoice amounts payable to vendors.
    • Determine who a customer service case is assigned.
    • Determine what background checks are required for an applicant.
    • Determine which contracts or services are available for sale.

The list likely goes on –numbering in the thousands…

13 of 22

Business Rules & Your Enterprise

  • Where do these business rules reside today for your Enterprise?
    • Backoffice systems such as an order entry system. Many likely reside in database stored procedures.
    • Business applications such as e-commerce web sites.
    • Likely a multitude of other locations.

  • The implication of this?
    • No central repository means limited visibility to what rules are used where.
    • Viewing and managing the rules can only be done by IT resources.
    • Changing rules is a costly, time-consuming and error-prone exercise.

14 of 22

Choosing a BRMS

Op

Open Source

*Now Oracle Policy Automation

15 of 22

How do I Choose?

  • Nearly all of the BRMS’ shown on the previous slide share more similarity than differences. They all use the same Rules algorithm (Rete), and provide some sort of API access via web services.
  • They all provide a means for cataloging, managing and versioning of rules.
  • To various degrees, most provide a graphical means for editing rules, and typically support “domain specific language” support (i.e,. more “English-like” vocabularies for writing rules).

16 of 22

JBoss Drools

  • Drools is the most well-established open source rules engine, and is supported by JBoss/RedHat.
  • Thousands of enterprises use Drools. It’s proven to scale, and it continues to evolve at a brisk pace.
  • Drools now is deeply integrated with jBPM, which is JBoss’ Business Process Management system.
  • Drools also includes support for Complex Event Processing (ESP) via it’s Fusion plugin. ESP allows real-time monitoring of all business events to identify anomalies.

17 of 22

Drools & jBPM

Drools & jBPM are now tightly integrated. The implication of this is that decision points within your business process models can driven by your business rules.

18 of 22

Integrating Drools

Jboss Drools now includes an integration framework using Apache Camel.

Camel is a lightweight Enterprise Service Bus that allows Drools to be exposed as a services API (i.e., “Decision Service”). This makes it easy to call Drools form a variety of clients using nearly any programming language.

19 of 22

BRMS Roadmap for Your Enterprise

Identify Use Case

Select a target application for the first implementation. For example, a new web application.

Harvest Business Rules

Identify all business rules used by the application. If necessary, remove them from PL/SQL code etc.

Populate BRMS

Add the identified rules in the BRMS. Create procedures to populate working memory.

Create Decision Service

Publish the rules as an API using a decision service. Use the rules in the new application.

Rather than attempt to build a comprehensive collection of all business rules, instead build incrementally. This reduces risk

and builds organizational

familiarity.

20 of 22

Dissecting a Drool Business Rule

rule "ZipMissing"

dialect "mvel"

when

$request : ValidateClaimForAuthorization( propertyZipCode == "" )

then

System.out.println("Invalid Request - ZipCode is missing.");

result.setResultCode(102);

result.setResultDesc(Constant.ERROR102);

end

An “object type” restraint.

public class ValidateClaimForAuthorization {

private int vendorSiteId;

private String jobNumber;

private String propertyZipCode;

private int workAsgnGenSeq;

private String operationSource;

public String getPropertyZipCode() {

return propertyZipCode;

}

public void setPropertyZipCode(String propertyZipCode) {

this.propertyZipCode = propertyZipCode;

}

A “field/method type” restraint.

21 of 22

What’s Next

  • A follow-up presentation will discuss how to configure Drools integration using Apache Camel.

22 of 22

Sources

  • Wikipedia

  • http://bs.doag.org/formes/servlet/DocNavi?action=getFile&did=258698&key=

  • http://www.jboss.com/pdf/JBossBRMSDataSheet.pdf