JBoss Rule Engine Kie Drools 6.3.0 Final Tutorial (1)

Source: Internet
Author: User
Tags jboss

Objective

There are few tutorials on the Kie DROOLS Workbench (JBoss BRMS) in the world, and there are only a few of them that have been translated using machines (the unintelligible ones) or some tutorials based on the old version of JBoss Guvnor or 5.x, and these tutorials are " Lack of arms and legs ", the beginner does not know what it is doing? Are you capable? Be able to solve any problems in your system.

So I wrote a few examples myself, the entire latest English version of the Kie DROOLS 6.3.0.Final official tutorial to string up, for readers to use as a starting point and the relevant concept of SOA to promote the first step.

This tutorial is divided into "three" sets.


What is a rule engine





Rules are best practices that enable business people to drive the entire enterprise process






The contradiction of business rules in realization


Business Rules Technology


The purpose of introducing business rule technology

People who use the system

    • Give business managers the right to create, modify, and maintain business policies (rules)
    • Increase business Agility
    • Enhanced transparency of business processes, business rules can be managed
    • Reduce the reliance on IT staff
    • Avoid the risk of future upgrades
for IT developers
    • Simplify system architecture and optimize applications
    • Improve system maintainability and maintenance costs
    • Easy integration of systems
    • Reduce the cost and risk of writing "hard Code" business rules

What is a rule engine

    • One or more facts can be mapped to one or more rules
    • Accept data entry, interpret business rules, and make business decisions based on business rules

A simple example



Why use the rules engine from the perspective of an IT technician?

    • Separating business logic from application logic and data
    • Simple! -The rules have a very simple structure
    • Enable business users to develop and maintain rules to reduce costs
    • Declarative programming
    • Performance and Scalability
    • Solve complex and compounded problems with a large number of fine-grained rules and factual interactions


demo-life New Excellent variable universal life insurance rules



demo-Life The IT realization of the insurance rules of the new remarkable variable universal life insurance


Exemption from physical examination cumulative ceiling table in the Rule engine implementation:



What is a brms?
What is brms-consider two issues (IT manager perspective)




What is brms-consider two issues (developer ease of use perspective)




Brms-business Rules Management System



A good brms should have the characteristics of



Two important concepts in brms: Factor, formula




The relationship between factor and formula from the point of view of business


The relationship between factors and formulas from the perspective of it



A system logic architecture based on BRMS


This logic diagram is a bit complicated, many people will feel "unintelligible", OK, not urgent! We will come back to it in the following article.




JBOSS Drools & Guvnor


There are many well-established rules engines in the world, such as IBM's Ilog,pegga Rulz (Pegasus), the most famous JBoss Rulz in the open source that we are going to introduce here.

Jboss Rulz was originally a built-in rule engine that was based only on the. Drools rules file, which later evolved into a "rule management system" called BRMs, and its brms is known as Guvnor. Later, after JBoss guvnor5.x, it changed its name to "KIE Drools WorkBench".





There are few tutorials on the Kie DROOLS Workbench (JBoss BRMS) in the world, and there are only a few of them that have been translated using machines (the unintelligible ones) or a few tutorials based on the boss's JBoss Guvnor or 5.x, and these tutorials are " Lack of arms and legs ", the beginner does not know what it is doing? Are you capable? Be able to solve any problems in your system.

So I wrote a few examples myself, the entire latest English version of the Kie DROOLS 6.3.0.Final to string up, for readers to use and as a starting point to promote the concept of SOA as the first step.


Guvnor Core functionality-the best open source rule engine




Installation and use of KIE drools6.3.0.final


Preparing the installation files and environment-environment


    • CentOS 6
    • mysql5.5.x or above
    • Apache-tomcat-7.0.67.zip (Tomcat7.0.4 or above)


These environments, readers should be installed on their own.


Preparing to install files and environments-must software



    • Kie-drools-wb-6.3.0.final-tomcat7.war
    • Drools-distribution-6.3.0.final.zip
    • A jar file to be used for the Lib directory of Tomcat7, which includes:

Jboss-jacc-api_1.4_spec-1.0.3.final.jar
Kie-tomcat-integration-6.3.0.final.jar
Slf4j-log4j12-1.7.7.jar
Log4j-core-2.1.jar
Log4j-api-2.1.jar
Log4j-slf4j-impl-2.1.jar
Slf4j-api-1.7.7.jar
Javax.security.jacc-api-1.5-javadoc.jar
Btm-2.1.4.jar
Btm-tomcat55-lifecycle-2.1.4.jar
Jta-1.1.jar
Database Driver (Mysql-connector-java-5.1.38.jar)


Above 12 dependent files if the reader is not in a moment to search, it doesn't matter I uploaded them here: droos6.3.0 in Tomcat when the missing package. zip


Start installation
1. Copy all of the following files to the Tomcat Lib directory


2. After opening eclipse, enter the following address according to Help->install new software
http://download.jboss.org/drools/release/6.3.0.Final/org.drools.updatesite/



3. Unzip the Drools-distribution-6.3.0.final.zip in the current directory

4. Unzip the Kie-drools-wb-6.3.0.final-tomcat7.war in the current directory
and renamed to Kie-drools after copying into Tomcat's WebApps directory.
5. Modify the Persistence.xml file in the D:\tomcat7\webapps\kie-drools\WEB-INF\classes\META-INF directory


The original use of the project H2dialectChange into Mysql5dialect


<properties>      <!--property Name= "Hibernate.dialect" value= "Org.hibernate.dialect.H2Dialect"/-->      <property name= "Hibernate.dialect" value= "Org.hibernate.dialect.MySQL5Dialect"/>      <property Name = "Hibernate.max_fetch_depth" value= "3"/>      <property name= "Hibernate.hbm2ddl.auto" value= "Update"/>      <property name= "Hibernate.show_sql" value= "false"/> <property      name= " Hibernate.transaction.manager_lookup_class "value=" Org.hibernate.transaction.BTMTransactionManagerLookup "/>      <!--BZ 841786:as7/eap 6/hib 4 uses new (sequence) generators which seem to cause problems--      <propert Y name= "hibernate.id.new_generator_mappings" value= "false"/> </properties>


6.in theTomcatof theconfAdd a file name to the directory:btm-config.propertiesof the file
The contents are as follows:

bitronix.tm.serverid=tomcat-btm-node0bitronix.tm.journal.disk.logpart1filename=${btm.root}/work/ btm1.tlogbitronix.tm.journal.disk.logpart2filename=${btm.root}/work/ Btm2.tlogbitronix.tm.resource.configuration=${btm.root}/conf/resources.properties

7. In the Tomcat conf directory, add a file named: Btm-config.properties file
resource.ds1.classname=bitronix.tm.resource.jdbc.lrc.lrcxadatasourceresource.ds1.uniquename=jdbc/ Jbpmresource.ds1.minpoolsize=10resource.ds1.maxpoolsize=20resource.ds1.driverproperties.driverclassname= Com.mysql.jdbc.driverresource.ds1.driverproperties.url=jdbc:mysql://192.168.0.101:3306/drools?useunicode=true &characterencoding=utf-8resource.ds1.driverproperties.user=kieresource.ds1.driverproperties.password= Aaaaaaresource.ds1.allowlocaltransactions=true

8. Modify Context.xml in the Conf directory of Tomcat
Add the following content:

<resource name= "jdbc/jbpm" auth= "Container" type= "Javax.sql.DataSource" driverclassname= "Com.mysql.jdbc.Driver"     url= "Jdbc:mysql://192.168.0.101:3306/drools?useunicode=true&characterencoding=utf-8"     username= " Kie "     password=" aaaaaa "     maxactive=" "     maxidle=" 1 "maxwait=       "/> "

9. Modify Server.xml in the Conf directory of Tomcat

Add the following content:




be sure to join the top


10. Modify Tomcat-users.xml in the Conf directory of Tomcat
Add the following content:


<user username= "Tomcat" password= "Tomcat" roles= "Admin,manager,manager-gui"/>

This user is used to access drools Kie


11. Create a schema in MySQL named Drools
and assign a user to the schema, if the user is accessing MySQL remotely, remember that the user wants to build a format of% (or [email protected] address), because Drools will create 39 tables in the corresponding DB by JPA at the first run.




12. Modify the catalina.sh file under the Tomcat directory bin
Add the following content

export Catalina_home= "/OPT/TOMCAT1" Export catalina_opts= "-dbtm.root= $CATALINA _home-dbitronix.tm.configuration=$ catalina_home/conf/btm-config.properties-djbpm.tsr.jndi.lookup=java:comp/env/ transactionsynchronizationregistry-djava.security.auth.login.config= $CATALINA _home/webapps/kie-drools/web-inf/ CLASSES/LOGIN.CONFIG-DORG.JBOSS.LOGGING.PROVIDER=JDK "Export java_opts="-d64-server-showversion-xms1024m- xmx1024m-xx:permsize=256m-xx:maxpermsize=256m-xx:cicompilercount=8-xx:+usecompressedoops-xx:-d ontcompilehugemethods-xss256k-xx:+aggressiveopts-xx:+usebiasedlocking-xx:maxtenuringthreshold=31-xx:+ Cmsparallelremarkenabled-xx:+usecmscompactatfullcollection-xx:+usefastaccessormethods-djava.awt.headless=true- XX:+USECMSINITIATINGOCCUPANCYONLY-XX:+USEGCOVERHEADLIMIT-XX:+USECONCMARKSWEEPGC-XX:+USEPARNEWGC-XX: Maxgcpausemillis=200-dorg.kie.demo=false "


Note:


1. Here my tomcat is placed under the/opt/tomcat1 of CentOS, so my catalina_home settings are replaced with the path of your Tomcat

2. The function of parameter –dorg.kie.demo=false is to run Kie-drools without Internet environment, if not add this parameter kie-drools will go to git to try to load Kie-drools demo at each run. If your server is a virtual machine or a non-Internet environment, it will cause the entire war project to fail if it throws a suspected memory leak exception due to an Internet connection timeout.

3.\This symbol must have a space before and after each line, and there are spaces at the beginning of each row, the function of this symbol is in the Linux console interface, a line is too long, divided into multiple lines of writing but can be connected to a line of execution.
Start typing in the Tomcat/bin directory:./catalina.sh start Tomcat and observe the log file in the Tomcat/logs directory:



Open a IE , enter the following address: Http://192.168.0.101:8080/kie-drools you can see Kie -drools the main interface.



Use of Kie
Use Tomcat/tomcat (user with Admin/analyst role configured in the Tomcat-users.xml file to log in)





Create a new project




As you can see, project in Kie-drools is actually a maven project

Create a new rule in project in order to practice, we will create a new rule, which is simple:


Suppose there is a reimbursement process, need to go through the department manager approval to finance, if the employee's reimbursement amount is greater than 5,000 then the department manager needs approval, but also report to the general manager for approval.


This is a business rule, assuming that the general manager said, "More than 5,000 will I batch, I am too bored, changed to more than 10,000 pieces before I need to review it", think about our traditional approach.



Using Kie-drools writing rules-establishing factors the rule involves a formula Money>x
The rule involves a factor, money


In the light of the above, we first establish the factor



This data object is a factor



You can write this pojo in Eclipse and copy it directly to the Kie-drools data Object editing interface:
Package Org.sky.threshholdrulz;public class Paymentinfo implements java.io.Serializable {static final long Serialversionuid = 1l;public Paymentinfo () {}private int moneyamount = 0;private String Decisionpath = "";p ublic void SetM Oneyamount (int amount) {this.moneyamount = amount;} public int Getmoneyamount () {return this.moneyamount;} public void Setdecisionpath (String path) {this.decisionpath = path;} Public String Getdecisionpath () {return this.decisionpath;}}



Don't forget to click on the "SAVE" button.
Writing rules with Kie-drools-rules


The rules read as follows:
Package Org.sky.threshholdrulz;no-looprule ' approval decision by manager '    when        m:paymentinfo (moneyamount >5000);    Then         Modify (M) {Setdecisionpath ("GM")};endrule ' approval decision by general manager '    when        m:paymentinfo (moneyamount<=5000);    Then         Modify (M) {Setdecisionpath ("M")};end


Using Kie-drools writing rules-Test rules
Our rule is actually simple:


If the paymentamount>5000 in the Paymentinfo factor, then the Decisionpath return in Paymentinfo is the string "GM".


If the paymentamount<=5000 in the Paymentinfo factor, then the Decisionpath return in Paymentinfo is the string "M".



Using Kie-drools Writing Rules-wizard-style test Scenario


Using Kie-drools writing rules-creating data for test cases









Using Kie-drools writing rules-run tests

Using Java program invoke rules-rules stored locally











End this tutorial
The following tutorial will explain how to build the. drools file onto our own Kie-drools Workbench 6.3.0.Final, and then use Java code to access the content remotely, which is currently in the domestic blog and forum almost no information, The author also by looking at the source code and look at the official documents summed up.
Its remote access is divided into two types: stateful (stateful) and stateless (stateless) 2 kinds, the text will also give a corresponding comparison and explanation.

JBoss Rule Engine Kie Drools 6.3.0 Final Tutorial (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.