Rules hot deploy using Drools / Guvnor – part 1
A SOA well done should be developed along the lines of business for which the architecture is being developed. One example is an insurer, where the services may well be made for each sector of insurance offered, as well as a customer base. Thus, if the insurer will act in a new class of insurance, all she has to do is to reuse the customer service, to offer these new portfolios.
However (and still using the example of insurance companies) should be noted that the selection of new users must abide by certain rules (eg, an insured can not be less than eighteen years), it should also be noted that these rules are not always immutable (and if the insurer decides that insured below eighteen years may be accepted only in life insurance, what if, during the operation of the system, the system user decides that insured under eighteen years can only be accepted with parental consent?).
To reflect this flexibility, the architecture SOA takes the concept of Business Rules. Are rules that are usually understandable by business analysts and can be easily changed. Some engines expose those rules in the form of web services and other options to facilitate the relaxation of such. Some also facilitate hot deploy rules to allow this flexibility.
To illustrate this concept of + hot deploy rules, created this tutorial on how to develop rules from the Drools API, post them on JBoss Guvnor and eat them so performative.
Why exemplify using Drools Guvnor + (or JBoss BRMS)?
The JBoss Guvnor is a system of governance rules that open source has an extremely user-friendly management interface. Also, your engine has, so native systems that facilitate the hot deploy and manage these rules natively through Apache Jackrabbit .
Below is the print screen splash screen Guvnor:
What terms need to know when using Drools?
- Package: logical organization to hold a collection of rules (similar to packages of Java classes).
- Model: entity that will store the data input and output rules.
- Fact finding that will cause a rule to run (similar to a if, in Java).
- Rule: snippet of code that, given certain facts, it will run.
- Snapshot: compiling the package at some point, which is what effectively will be used to generate a new snapshot (ie, is a “snapshot” of the package).
What this tutorial applies to versions
This tutorial is based on version 5.0 of Guvnor, based on JBoss AS version 4.2.3. The set is available for download here .
How do I create a rule using Drools?
Syntax (simplified) to create rules in Drools is:
package seguradora declare Segurado idade : Integer status : String end rule "menores de idade não são autorizados" when seg : Segurado( idade >= 18) then seg.setStatus ("AUTORIZADO"); end
In code, you can see the model “insured” who possesses the attributes age (like Integer) and status (of type String – the fact that Integer and String classes belong to the package java.lang, it is not necessary to put the fully qualified name of them). The rule, in the clause “when”, and receives an insured assigns the variable “sec”. The fact here is the excerpt:
Segurado( idade >= 18)
That is, the rule only evaluate the code in the clause then if, and only if the insured has an age attribute with a value greater than or equal to 18. If so, the words:
will be evaluated. Note that here it is developed purely in Java code, or ceases to be native to the Drools.
How can I make this rule will deploy Guvnor
To accomplish deploy this rule, just follow the steps:
- Create a new category, the Administration
- menu Knowledge Bases , create a new package (package );
- Knowledge Bases , select the option to create a new rule, as the example:
- The written text box that appears, type the text of the rule.
- Click Validate
- If everything is OK, click Save changes
There, the rule is set to deploy. For the implementation of the rule, however, you must perform some coding, I’ll post next post. See you there!