Implementation of the rules engine

Technical innovation description of rule engine

background

         Committed to providing customers with the technology of customer loyalty programs, the development and operation of the Points Mall for many customers in different industries including post and telecommunications, banking, aviation and other industries has been widely recognized by customers. But how to offer a points program (i.e. customer loyalty program) to customers? Moreover, the input elements of point programs in different industries (for example, airlines care about different cockpits, and banks may care about different card levels), and the point logic is even different (reward points based on a single transaction, rewards based on a certain range of times or total quota, etc.). It is bound to involve the customization of point programs in different industries. How to make it easier for business personnel to manage point programs without restarting the system after customization? All these requirements make it necessary to develop a set of point plan engine (rule engine), so that it can face the point plan with different logics in different industries. After I joined the technology, I initially developed the rules engine component of the company's independent technology with the xx points demand as the entry point .

Rules Engine Definition

         The rule engine is an engine system that can run many rule templates (hereinafter referred to as templates), which are used to run different rules and logics in different industries. There is no need to re-develop the rule system for each industry, only the template part that has changed can be developed, which shortens the customized development time for different rules and improves the implementation efficiency.

 

 

structure and design

The rule engine is a set of computing framework, which separates the maintenance rule logic from the code and maintains the rule logic conveniently.

The engine structure is as follows:

Engine part (integral part):

Templates are loaded automatically (no restart required)

Save the compiled class file of the template in the shared file system instead of the classpath of the Java virtual machine . This allows classes to be loaded dynamically without requiring a system restart. The advantage of saving in a shared file system is that this class is accessible in a clustered environment .

To load classes to the file system, dynamic class loading technology is required.

 

Regular resident memory

Whenever a rule sends a change, update the rule in memory.

Scan the rules on the hour (all day), and load the rules that need to be activated

When running a rule, it is read from memory first, and the memory is not loaded into the file system.

 

 

Provide session data frame

Provides session data in key-value structure and provides management functions.

 

Template section (integration rules)

Input feature customization

 

Define the basic transaction type PialTrade, the elements include commonly used user id , transaction code, transaction time, transaction location, transaction delivery terminal type, quantity, name, and amount of commodities involved in the transaction; other industries can inherit this object and expand.

 

The engine does not know the specific business object, and the template corresponds to the specific business object.

 

output features fixed

The output features are:

Whether the calculation result is successful,

points earned,

Text information of the note

 

Can manipulate session data

Use the read and save operations of session data provided by the engine .

Integral intermediate data, that is, the session data mentioned above.

 

Business flow to be integrated: flow sent to the external business system of the rule engine.

Calculate the calculation result: that is, the output result in the template.

 

Automatic  generation of rule parameters

Because the parameters of different templates are different, it is necessary to automatically identify the parameters in the template according to the pattern matching based on the characteristic word for the business personnel to input.

Such as the rule logic code:

        

String Merchant without points =rule.parameters.get(" merchant without points ");//@ Parameter description @ Merchant without points , separated by commas

It will automatically identify the parameter " merchant without points " , and the explanation of this parameter "merchants without points , separated by commas" .

 

 

benefit

Different business objects can be defined for different industries.

Defining Different Integral Logics

The template is uploaded online, and the new rule takes effect automatically

The point plan logic is resident in memory, no need to access the hard disk, and the calculation is extremely fast. Tested by the Beijing core team testers, it can handle 500 concurrency with ease.

how to use

Business personnel write rules and logic files according to market needs.

> Template engineers write corresponding templates ( java files) according to the logic files provided by the market, test and upload them.

 

       1 ) Available to get transaction object, rule parameter value

       2 ) Write logic. Including the comparison and judgment of numerical values ​​and characters, the inclusion judgment of characters, the four arithmetic operations of numerical values, and so on.

       3 ) Write the returned integral result object.

 

 

The business selects the template, determines the parameters in the template (such as the percentage of points, which pos to filter, etc.) and establishes a rule.

The engine automatically loads this rule and is responsible for its interpretation.

When the transaction data of the business system is sent to the engine, the engine combines the business data with the template and executes the template.

The points output by the engine can be connected to the account system (or not), and the points can be credited into the account.

        

application

Points Rewards Program

All other places where judgments or calculations are made based on the use of the given rules.

Such as lottery (defining the probability of winning prizes at each level, the number of prizes, and the number of single-user draws).

The rules of various activities in the mall, etc.

Applications

         Based on this engine,

In 2015 , the xx rule template was developed:

Continuous check-in rewards, order rewards, etc.

In the summer of 2015 , in the Points 1.5 version, the center-side reward template was developed:

Registration rewards, referral rewards, points transfer-in and transfer-out rewards, point consumption rewards, and point recharge rewards.

 

In 2016 , in the lottery interactive activities added in the Points Mall, the developed lottery template also runs on this engine.

                                                   

 

                                                                                             Xing Lijun, 2016.4 .

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326658281&siteId=291194637