Urule introduction

Due to the need of work, I refer to many excellent JAVA implementation of open source rule engine framework, such as Drools, but in the vast sea of people I found a visual configuration based on RETE algorithm rule engine, its name is Urule, the following extract from Urule official Wiki:

URule is a pure Java rules engine based on RETE algorithm. URule provides seven types of rule definition methods: wizard rule set, script rule set, decision table, cross decision table (PRO version), decision tree, score card and decision flow. With the Web-based designer, it can quickly realize the definition, maintenance and release of rules.Copy the code

Github project address Official Wiki address

Usage scenarios

One day, when Loye was stroking the code, the product MM came to loye to review the requirements of a daily login activity. The requirements were like this:

 -5Users below level login send5Yuan red envelopes -5Level above user login send10Yuan a red envelopeCopy the code

Leaflet students a look, So easy! Two lines of code are knocked down to test the line:

// Login event trigger code
if (user.getLevel() <= 5) {
    // Give a red envelope of 5 yuan
    rewardGenerator.send("Five yuan red envelope");
} else {
   // Give a red envelope of 10 yuan
    rewardGenerator.send("10 yuan red envelope");
}
Copy the code

After a day, operation GG looking for product MM feedback that the activity is too hot, bedding wool is too serious, to modify the rules:

- Users must be authenticated with their real names5Users below level login send3Yuan red envelopes -5Level above user login send7Yuan a red envelopeCopy the code

Xiao Ye finished the logic with a calm face:

// No real name authentication will be rewarded!!
if(! user.isRealNameAuth()) {return;
}
if (user.getLevel() <= 5) {
    // Give a red envelope of 3 yuan
    rewardGenerator.send("Three yuan red envelope");
} else {
   // Give a red envelope of 7 yuan
    rewardGenerator.send("7 yuan red envelope");
}
Copy the code

A week later, the operation GG found the product MM and said that the gameplay was too simple and did not achieve the effect of the activity. The demand was changed to the following:

- Users must be authenticated with their real names5Level below users - login send3Yuan red envelope; - Share articles to moments every day1Lucky draw opportunities; - Forum reply15Word above10giving50Yuan reduction coupon; -5Level above user - login send7Yuan red envelope; - Share articles to moments every day2Lucky draw opportunities; - Forum sign-in delivery1Lucky draw opportunities; - Forum reply1Gift above words100Yuan reduction coupon;Copy the code

The expression of xiaoye, who just got PRD, is like this:

So lobular classmates began baidu have operation GG to be able to configure their own generation of relevant rules of some of the framework of what, really have! It would look something like this:

(Form of decision set)

It could also look like this:

(Decision tree form)

You can even play it like this (which is a terrible way to score) :

(Scorecard form)

The above three forms are only the tip of the iceberg of Urule, the important thing is that there is no visual configuration! Much more comfortable than writing dead code! Free the hands of programmers (of course, it depends on the situation and needs)

Therefore, Xiaoye integrated Urule into his project without saying a word, and configured a rule tree according to the requirements:

After the matter is done, lobular students hurriedly Urule masturbation online, then the later rules by the operation GG configuration is good