Replace code with rule engines

xiaoxiao2021-03-06  41

Author: Clan in Liang Bing

The basic principle of the business rules management system is to replace the business logic "Curing" in the application system with one or more rule engines. A perfect BRMS can achieve full management of the entire life cycle of business rules.

Full lifecycle management of business rules is shown in Figure 1. BRMS is similar to the database management system (DBMS) in the application system. It is the cornerstone of other high-end applications. 2 is a location diagram of BRMS in the IT architecture given by Giga Information Group.

How does business rules management implement?

Business Rules

A business rule contains a set of conditions and operations executed under this, which represents a service logic for business rules applications. Business rules should usually be developed and modified by business analysts and strategy managers, but some complex business rules can also be customized by technicians using object-oriented technical languages ​​or scripts. The theoretical basis for the business rules is to set one or more conditions while trigger one or more operations when these conditions are met.

Rule engine

This is an assembly embedded in the application. Its task is to test and compare the data objects currently submitted to the engine with the business rules loaded in the engine, activating business rules that meet the current data status, according to The execution logic declared in the business rules, triggers the corresponding operations in the application.

At present, mainstream rules engine components are mostly based on Java and C programming locations. In November 2000, Java Community Process (JCP) organization began to draft the API standard of the Java rules engine, that is, JSR 94 specification. Participation in JSR 94 drafted with BEA, IBM, ILOG, Oracle, Novell, ATG, Unisys, Fujitsu and other famous software companies. JSR 94 officially finalized on November 25, 2003, supporting the rules of JSR 94 standards, almost simultaneously introducing the market, including iLog's JRules and Blaze's Advisor.

How to use the rules engine

Since the rule engine is a software components, only developers can use and control it through the program interface, the rule engine includes at least the following APIs: API of the load and uninstall rule set; data operation API; Engine Executed API. Developers use the rules engine in the program basically follow the following five typical steps: Create a rule engine object; load the rule set or replace the rule set to the engine; submit the data object set to the engine needs to be processed by the rule; command engine execution; Export engine execution results, withdraw the processed data from the engine. After using the rule engine, many program code involving business logic is basically replaced by these five typical steps.

An open business rules engine should be "embedded" in any location of the application, the rule engine of different locations can use different rule sets to handle different data objects. In addition, there is no limit to the number of used engines.

Internal implementation of the rules engine

The basic mechanism of the rule engine is: Retrieving the data object submitted to the engine, based on the current attribute values ​​of these objects, the relationship between them, the implementation of these rules from the rule of the rule that is loaded into the engine, and creates the execution of these rules. . These instances will be executed in accordance with some priority when the engine receives the execution instruction. Generally, the rule engine consists of several parts: working memory, used to store data object collections referenced by the engine; rule execution queues, used to store activated rules, implement instances; static rules area, used to store all loaded Business rules, these rules will be organized according to some data structure. When the data in the workspace changes, the engine needs to quickly perform instances in the rule execution queue according to the status of object in the workspace. The structure of the rules engine is shown in Figure 3.

Any rule engine needs to solve the efficiency of reasoning mechanisms and rule conditions matching the rules.

When the engine is executed, the rule execution instance will be executed according to the priority order in the rule execution queue, and the execution of the rule may change the data objects of the workspace, so that some rules in the queue will fail because of the change of conditions It must be revoked from the queue or activate the rules that do not meet the conditions to generate new rules to enable instances to enter the queue. Then, a "dynamic" rule execution chain, a reasoning mechanism for forming a rule. The "chain" reaction of this rule is completely data driven by the work area. The efficiency of the rule conditions determines the performance of the engine, the engine needs to quickly test the data object in the workspace, and discover the rules that meet the rules from the loaded rules, generate rules enforcement instances. Charles L. Forgy of the University of Carnegie Mellon in 1982 invented a RETE algorithm that solved this problem well. Currently, the world's top commercial business rules engine products basically use the RETE algorithm.

BOM gives a rule industry feature

Business rules must be for a certain business, different services have their own unique business model - business object model (BOM). BOM provides the vocabular vocabulary for business rules, and is more designed by business system analysts, which is implemented by developers. From the object-oriented programming point of view, the BOM is a simplified class diagram, there is a class name, class attribute, method of classes, etc. These elements will be the basic "vocabulary" in the business rules language. The source of the BOM can be the Java object model, the C object model, XML Schema, Web service definition, etc.

Assuming that we have a simple pet shop shopping cart application, in this application, customers can put in various pets and related items in the shopping cart. The business object collection of this application can have SHOPPINGCART, Customer (User), Item (entry), and ItemType (entry type).

The grammatical representation of business rules is the business rule language. Since the user of the rule language mainly has two types: business personnel and technicians, the rule language is generally divided into two categories: "Procedure Technology" rule language, it is technically very technical, the readability is weak, and it is suitable for IT Using the technician, each rule engine developer has its own set of rule language syntax of "program technology", but the OASIS organization defines rule language specification in different applications, including SRML (Simple Rule Markup Language), BMRL (Business Markup Rule Language) and RuleML (Rule Markup Language), etc .; "Business" rule language, it is the language used by business people, must have non-technical and customizable, usually it needs to be "translated" before Rule engine analysis. BRMS must provide this "translation" mechanism, while developers must implement mappings from the "Business" rule language to "program" rule language.

"Business-oriented" rule language may have a change from grammar or statement structure, and different industries may have their own "javel". A good BRMS should provide a perfect rule language framework that can quickly customize different "jaices" for business people, otherwise the business is still unable to really become the owner of the business rules.

How does "simple" rules interconnect?

Business rules have a very obvious feature: simple. Each business rule only describes its own unique condition and the condition of the condition, and the business rules are not concerned with other relationships with other rules, such as priority, mutual exclusive relationships, and relationships. Each business rule itself can have its own properties, called element information, can be used to handle correlations between rules, such as the engine can use the priority of the rules to perform the rules in order. Some BRMS also provide a custom function called "rule stream". The rule stream is a chart that defines the order of solving problems or executes business processes. Similar to the unified modeling language (UML), a set of transformation logic is performed by a set of tasks and defining these tasks. One conversion is controlled by condition, and this conversion can only be completed when the restriction condition is "true".

These tasks can be rule tasks, function tasks or sub-rule stream tasks. The rule task contains a set of rules to be performed as a task body, and the rule execution logic is strictly controlled by the task properties set by the user. These attributes determine the rules, rules trigger policies, execution algorithms, etc .; function tasks contain script code to be performed as a task body; sub-rule stream task, the subregional stream of the subordinate will be executed after the task begins.

In order to facilitate developers and business personnel management business rules, BRMS must provide tools with intuitive user interfaces to implement business rules management. The rules management tool should at least have the following functions: customization and editing of rules, customization of rules streams, decision forms of decision forms, rules, rules, rule validity test, rule organizational structure, rule template customization, rule library access Permissions control, rule change history record, rule document management, etc.

· Small information 2 ·

The business rules management system is actually a set of tools, including: rule engine, rule base, rule language framework, rule management integrated development environment. The basic working principle of the business rules management system is shown in the figure.

Rule Engine (Rules Engine)

It is a software component that executes business rules, which is embedded in the program and is the core element of the business rules management system. The type of rule engine is: simple, data center type, and transactional.

Rules repository and its service mechanism

Used to store rules and rule metadata and properties related to rules. It provides a set of tools for storage, classification, query, version control, permission control, test, submission, etc., the status and validity of the rules can be tracked. The rule library can rely on the file system or database management system.

Rule language framework (Rules Language Framework)

The rule language is generally divided into two categories: "Procedure Technology" rule language, users are technicians; "business-oriented" rule language, users are business people. The rule language framework provides support for customized "business" rule languages.

Rule Management Tool (Rules Management Tool)

The graphical tools used to manage, create, modify, and deploy business rules, easy to use, in addition to developers, business people can also use this set of graphics tools to manage rules.

Rule Integrated Development Environment (Rules IDE)

General rules integrated development environments only have rule editors, while advanced rules integration development environments can achieve management of rules and rules libraries: such as rules creation, classification, retrieval, modification, version control, permission management, etc .; "Online" debugging of a rule engine; conflicting the rule set, etc. A complete BRMS should provide rule management, rule deployment, rule analysis, rule customization, and design (Rules design and authoring)

转载请注明原文地址:https://www.9cbs.com/read-61477.html

New Post(0)