How to build a rule base based on a rule engine

 

A rules engine is a tool for technologists. At present, why technicians choose the rule engine to use is mainly based on the following situations:

    1. The business logic is separated from the program code. Implement business rules through configuration.

    2. The change of business rules can be directly modified and changed by the user through the web interface.

    For this type of demand, in fact, we generally have the following options:

    1. Select a rule engine to implement.

          Existing rule engine products can generally meet the above two requirements. You can implement business logic without code, such as Java, but use a rule language to complete it through a rule configurator. When users need to make changes, they generally provide a C/S or B/S version of the rule configurator to implement.

    2. Adopt dynamic language:

          By directly using JS or other dynamic languages ​​such as BeanShell, it is also possible to implement business logic without using Java code. It can also provide an editing interface for users to modify.

    3. Table configuration or custom formula

           Implement specific logic by defining a table or adding a certain custom formula syntax.

     The above solutions have their own advantages and disadvantages in different projects:

    1. Implemented by a rule engine, making the configuration of business rules more standardized and professional. At the same time, the general rule engine will perform version control on the modified records to facilitate operations such as tracking, testing, and recovery. The interface provided by the rule configurator is more user-friendly and more convenient for users to use. The disadvantage is that the architecture of the entire system will become huge, and someone needs to be specially responsible for the study of the rule engine, as well as related configuration and management tools.

    2. The implementation of dynamic language will be simpler for development. Dynamic languages ​​generally deal purely with logic, so interface design is easier. When using dynamic languages ​​at the same time, issues such as inheritance and mutual calls are rarely considered. The disadvantage is that the supported logic is relatively flat and relatively simple. At the same time, dynamic languages ​​require a learning process.

    3. It is the most commonly used in general projects through table configuration and custom formulas. Through a configuration table to achieve corresponding management, logic flow. This method is the most user-friendly, more convenient for users to operate, and has the fewest problems. The disadvantage is that it is not flexible enough, and the development workload is large.

    The above considerations are only from a technical point of view, how to code a technical work, and replace an implementation method because of the changing requirements. So that there will be no changes to the code due to changes in requirements. Because code changes will bring a series of problems, change process, testing, deployment and so on.

    But since we have separated the business logic related to the business from the program, we cannot just stay in the development and implementation stage. Instead, it should be incorporated into the client's management system. Become part of user system management. For example, we should at least consider how many business rules the user can view, which can be configured by the user, who has the permission to view, create, modify, and delete which business rules, who made the modification and when, and who is responsible for testing and testing. What was the result, when was the new modified business rule applied, etc.

    In this case, we cannot consider this implementation problem only from the perspective of rule engine tools, but from the perspective of rule base management.

    Therefore, whether we use a rule engine or a dynamic language, to implement business logic for users to maintain and modify. It should strengthen more management functions for user maintenance to make this work more standardized and standardized.

    To implement a business rule library, you need to consider the following issues:

    1. User rights management. The permission system of the existing application system is adopted, and corresponding permission settings for the rules are added.

    2. When setting rule permissions, you need to consider permissions such as viewing, creating, modifying, deleting, testing, reviewing, publishing, and executing.

    3. Consideration of rule classification. Consider a variety of ways to group, user role permissions are assigned according to rule groups.

    4. Rule version control: The version number of the rule can be set, and the label of the rule group can be set, so that the test release can be distinguished.

    5. Individual testing of rules: For the testing of rules, batch test cases can be set, and tests can be performed online.

    Of course, if the application system is clustered, clustering issues need to be considered. Therefore, the execution of the rules is preferably stateless.

    Separating business rules from the program for management is an effective means to solve the change of user needs. At the same time, we should use the idea of ​​rule base management to go one step further to achieve norms, standards and unity.

 

Guess you like

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