Rule engine and related product

By designing a general rule engine based on Spring SpEL expressions, the problem of low efficiency of the rule engine in the existing technology is solved, the efficient definition and execution of rules is realized, dynamic rule management is supported, and the flexibility and adaptability of the system is improved.

CN119539063APending Publication Date: 2025-02-28UNICLOUD TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411370968.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

Existing database-based rule engines require frequent access to the database, which affects the efficiency of rules execution.

Method used

A common rule engine based on Spring's SpEL expression is designed, including rule set configuration module, rule set management module, domain model design module, rule execution report module, engine execution result module, rule factory module, rule context module and rule executor. Through SpEL expressions, rules are defined and executed, and dynamic rule addition and management are supported.

Benefits of technology

It improves the work efficiency of the rule engine, reduces the complexity of rule definition and execution, supports rapid response to business changes, and enhances the flexibility and adaptability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119539063A_ABST
    Figure CN119539063A_ABST
Patent Text Reader

Abstract

The invention provides a rule engine and a related product. The rule engine comprises a rule set configuration module, a rule set management module, a domain model design module, a rule execution report module, an engine execution result module, a rule factory module, a rule context module, a rule executor and a dynamic rule adding module. Compared with the prior art, the rule engine provided by the invention has the advantages that simple definition and efficient execution of the rule are realized by utilizing the advantages of the Spring framework. Compared with an existing rule engine based on XML or a specific rule language, the rule engine has the advantages that a developer is allowed to use the SpEL expression to directly define the rule, and the efficiency of the rule engine is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a rule engine and related products. Background Art

[0002] With the continuous development of science and technology, people's work and life are moving towards intelligence. A rule engine is a software system used to define, execute and manage business rules. Business rules refer to rules used to describe business logic and constraints in a software system. For example, judging whether a user meets certain preferential conditions based on information such as the user's age, gender, income, etc., or calculating the discount rate of an order based on information such as the amount, quantity, and time of the order. Business rules usually need to be constantly modified and updated according to changes in business needs. Therefore, the rule engine can separate business rules from business applications, making it easier to modify, test and reuse business rules. Business rules can be dynamically configured and managed without modifying the code, which is an important means to improve software development efficiency and maintainability. The rule engine of the related technology is implemented based on a database, but the rule engine based on the database needs to frequently access the database, which affects the execution efficiency of the rules. Therefore, how to improve the efficiency of the rule engine has become a technical problem that technicians in this field need to solve urgently. Summary of the invention

[0003] Based on the above problems, the present application provides a rule engine and related products to improve the working efficiency of the rule engine.

[0004] The present application provides a rule engine, which includes the following modules:

[0005] A rule set configuration module is used to configure a rule set defined by a SpEL expression in a Spring configuration file or program, where each rule set contains one or more rules, each of which includes a rule name, a rule condition, a rule action, and a rule priority, and the rule condition is defined by a SpEL expression;

[0006] A rule set management module, used to manage the life cycle of multiple rule sets, which life cycle includes creating, updating and deleting rule sets;

[0007] The domain model design module is used to design the domain model of the rule engine. The domain model is used to determine the field attribute type information of the rule engine input parameter. The domain model is used to distinguish between embedded attributes and external attributes, and to design and implement different behavior logics according to different attributes.

[0008] A rule execution report module is used to generate an execution report after each rule is executed. The execution report includes the execution status, execution time, and all triggered rules and corresponding execution results;

[0009] An engine execution result module, used to obtain an execution result according to the execution verification level of the control rule, and the execution result is the output basis of the rule engine;

[0010] The rule factory module is used to load and manage rule sets, as well as manage and control the creation and destruction of rule engines;

[0011] The rule context module is used to store and transmit relevant data during the rule execution process;

[0012] The rule executor is used to call the execute method when receiving a business request, take the context of the passed-in rule as a parameter, determine the rules that meet the execution conditions according to the rule conditions and the context, and execute the rule actions corresponding to the rules that meet the conditions in order of rule priority;

[0013] The dynamic rule adding module is used to support the dynamic addition of new business rules when the program is running.

[0014] In a possible implementation, the rule executor uses a SpEL parser to parse, executes the business rules based on the SpEL parser, and returns the execution result of the rule based on the SpEL parser, where the execution result includes a Boolean value, a numerical value, and a string.

[0015] In a possible implementation, the rule executor supports parallel execution of multiple business rules.

[0016] In order to adapt to the rule engine provided by the present application, on the other hand, the present application also provides an application method of the rule engine, which is characterized by comprising:

[0017] In the Spring configuration file, a rule set, a rule executor and a rule context are defined through a rule set configuration module. The rule set is configured through a SpEL expression, the rule executor is used to process business requests, and the rule context is used to store data related to the current business;

[0018] When receiving a business request, the business application sends a rule execution request to the rule executor, wherein the rule execution request includes a rule identifier, parameters and context information;

[0019] The rule executor loads the corresponding business rule from the rule repository according to the rule identifier in the request. If the rule is not found in the rule repository, the rule executor dynamically loads the business rule from an external resource and updates the rule repository.

[0020] After the loading is completed, the rule executor creates an instance of the rule context and sets the data in the business request as attributes of the context;

[0021] The rule executor executes the rule action corresponding to the rule, and outputs the execution result based on the rule execution report module and the engine execution result module.

[0022] In a possible implementation, the rule action corresponding to the rule executed by the rule executor includes:

[0023] Determine the rules that meet the execution conditions according to the rule conditions in the rule set and the data in the context, and the determination is based on the calculation result of the SpEL expression;

[0024] For rules that meet the execution conditions, the rule executor executes rule actions in order of rule priority, and the rule actions can modify data in the rule context or generate output results.

[0025] In a possible implementation, the method further includes:

[0026] If an exception occurs during the execution of a rule, the rule executor automatically triggers the exception handling mechanism, performs a rollback operation, and generates a corresponding error report.

[0027] The present application also provides an electronic device, the electronic device comprising a processor and a memory:

[0028] The memory is used to store a computer program and transmit the computer program to the processor;

[0029] The processor is used to execute the steps of the above-mentioned rule engine application method according to the instructions in the computer program.

[0030] The present application also provides a computer-readable storage medium, characterized in that the computer-readable storage medium is used to store a computer program, and when the computer program is executed by an electronic device, the steps of the application method of the above-mentioned rule engine are implemented.

[0031] Compared with the prior art, this application has the following beneficial effects:

[0032] The general rule engine based on Spring's SpEL expression proposed in this application, compared with the prior art, this application takes advantage of the Spring framework to achieve concise definition and efficient execution of rules. Compared with the existing rule engines based on XML or specific rule languages, this application allows developers to use SpEL (Spring Expression Language) expressions to directly define rules. SpEL is a powerful expression language that supports operations on Java objects, making the writing of rules more intuitive and flexible. Developers do not need to learn new rule languages ​​or formats, which reduces learning costs and development thresholds and improves development efficiency. Many existing rule engines cannot flexibly add new rules at runtime, and usually require recompilation or restarting the system. Through the dynamic rule addition module of this application, users can add, modify or delete rules at any time according to actual needs when the program is running. This flexibility enables the system to respond quickly to business changes, support rapid iteration and continuous delivery, and meet the requirements of agility and adaptability in modern software development. The rule set management module of this application provides a more systematic rule management mechanism. By effectively managing the life cycle (creation, update and deletion) of the rule set, developers can more easily maintain and organize rules. This not only improves the manageability of the rules, but also reduces potential errors caused by redundant or outdated rules, ensuring the clarity and consistency of business logic. The domain model design module of this application enables the rule engine to better adapt to the needs of different business fields. By clearly distinguishing between embedded attributes and external attributes, users can design corresponding rule logic according to specific business scenarios. This flexible design ensures the scalability of the rule engine, enabling it to be widely used in various industries and scenarios. The introduction of the rule execution report module enhances the transparency and traceability of the rule execution process. The execution report generated after each rule execution records in detail the execution status, execution time, triggered rules and corresponding execution results. This provides important data support for subsequent auditing, analysis and optimization, making business decisions more scientific and reasonable. Through the engine execution result module, the rule engine can obtain the execution results according to the execution verification level of the control rule. This design not only improves the execution efficiency of the rules, but also provides users with more accurate feedback to help them adjust and optimize business strategies in a timely manner. The general rule engine based on Spring's SpEL expression in this application is significantly better than the prior art in the efficiency of rule definition. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0034] Figure 1 A schematic diagram of the structure of a rule engine provided for this application;

[0035] Figure 2 A flowchart of a rule engine application method provided in this application. DETAILED DESCRIPTION

[0036] As described above, with the continuous development of science and technology, people's work and life are moving towards intelligence. A rule engine is a software system used to define, execute and manage business rules. Business rules refer to rules used to describe business logic and constraints in a software system. For example, judging whether a user meets certain preferential conditions based on the user's age, gender, income and other information, or calculating the discount rate of an order based on the amount, quantity, time and other information of the order. Business rules usually need to be constantly modified and updated according to changes in business needs. Therefore, the rule engine can separate business rules from business applications, making it easier to modify, test and reuse business rules. Business rules can be dynamically configured and managed without modifying the code, which is an important means to improve software development efficiency and maintainability. The rule engine of related technologies is implemented based on a database, but the rule engine based on a database needs to frequently access the database, which affects the execution efficiency of the rules.

[0037] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0038] Figure 1 The schematic diagram of the structure of a rule engine provided in this application includes the following modules:

[0039] Rule set configuration module 101:

[0040] The rule set configuration module 101 is used to configure a rule set defined using a SpEL expression in a Spring configuration file or program, wherein each rule set contains one or more rules, each of which includes a rule name, a rule condition, a rule action and a rule priority, and the rule condition is defined using a SpEL expression.

[0041] In the rule engine, the rule set configuration module is an important part of the general rule engine based on Spring's SpEL expression. The main function of this module is to define and configure rule sets, so that users can flexibly manage and use business rules. Specifically, the functions and features of the rule set configuration module include the following aspects:

[0042] Definition of rule sets: The rule set configuration module allows users to define rule sets using SpEL expressions in Spring configuration files or program code. Each rule set can contain one or more rules, and users can flexibly organize and manage these rules according to business needs. This flexibility makes the configuration and update of business logic simpler and more intuitive.

[0043] Rule composition: Each rule consists of multiple parts, including rule name, rule condition, rule action, and rule priority. The rule name is used to identify the rule, the rule condition is defined by SpEL expression, the rule action is the operation to be performed when the rule condition is met, and the rule priority determines which rules should be executed first when multiple rules meet the conditions. This structured definition makes the management and execution logic of the rules clearer.

[0044] Since SpEL is already integrated into the Spring framework, users do not need additional dependencies or complex configurations when using rule set configuration modules. This integration makes system construction and maintenance easier, allowing developers to focus on the implementation of business logic rather than complex technical details.

[0045] The rule set configuration module supports dynamic loading and updating of rule sets when the program is running. Users can add, modify or delete rules at any time according to actual needs. This dynamism enables the rule engine to quickly adapt to business changes, support real-time decision-making, and improve the reusability and scalability of rules.

[0046] The rule set configuration module enables unified management of all rules. Users can easily view, modify and maintain rule sets to ensure the consistency and effectiveness of rules, while reducing errors caused by redundant or inconsistent rules.

[0047] Rule set management module 102:

[0048] The rule set management module 102 is used to manage the lifecycle of multiple rule sets, where the lifecycle includes creating, updating, and deleting a rule set.

[0049] In the rule engine, the rule set management module is an important part of the general rule engine based on Spring's SpEL expression, responsible for managing the life cycle of multiple rule sets. The functions and features of this module include the following aspects:

[0050] Lifecycle management: The rule set management module is mainly responsible for managing the lifecycle operations such as creation, update and deletion of rule sets. Through this module, users can easily add, delete, modify and check rule sets to ensure timely update and management of rules. For example, when business requirements change, users can quickly modify existing rule sets or add new rule sets to adapt to new business scenarios.

[0051] Centralized management: This module provides a centralized management mechanism, so that all rule set management operations can be performed in one place. This centralized management method simplifies the organization and maintenance of rules. Users do not need to search and modify rules in multiple places, reducing the probability of errors.

[0052] Version control: In practical applications, business rules often need to be adjusted and optimized over time. The rule set management module can support version control, allowing users to track historical versions of rules. When a new version of the rule is created, the old version can still be retained for rollback or reference when necessary. This version management ensures the stability and traceability of the rules.

[0053] Rule validity check: The rule set management module can perform validity checks when updating or adding rules to ensure that the new rules meet the predetermined syntax and logic requirements. This function can effectively prevent business logic problems caused by rule errors and improve system reliability.

[0054] Integration and configuration simplicity: Since the rule set management module is tightly integrated with the Spring framework, users do not need to make additional configurations or introduce complex dependencies when using it. The module uses the characteristics of Spring to achieve a simple configuration and usage process, so users can quickly get started and focus on the implementation of business logic.

[0055] Support dynamic update: The rule set management module supports dynamic update of the rule set while the program is running. Users can add or modify rules at any time without stopping the system, which enables the rule engine to quickly respond to changes in business needs and improve business flexibility and adaptability.

[0056] Collaboration with the rule factory: The rule collection management module works in conjunction with the rule factory module. The rule factory is responsible for creating and loading rule collections, while the rule collection management module ensures the effective management of these collections during their lifecycle. Through this division of labor, the system architecture is clearer and the collaboration between functional modules is closer.

[0057] Monitoring and reporting: The rule set management module can also integrate monitoring and reporting functions to record the status changes and operation logs of the rule set. Through monitoring, users can promptly discover potential problems and obtain the usage and performance indicators of the rule set to provide data support for subsequent optimization.

[0058] The rule set management module provides functions such as lifecycle management, centralized maintenance, version control, validity verification and dynamic update of rule sets. The design of this module not only improves the efficiency and reliability of rule management, but also provides important support for the flexibility and scalability of the Spring-based general rule engine, ensuring that the system can quickly adapt to changing business needs.

[0059] Domain Model Design Module 103:

[0060] The domain model design module 103 is used to design the domain model of the rule engine. The domain model is used to determine the field attribute type information of the rule engine input parameter. The domain model is used to distinguish between embedded attributes and external attributes, and implement different behavior logics according to different attribute designs.

[0061] In the rule engine, the domain model design module can be an important part of the general rule engine based on Spring's SpEL expression, responsible for designing and managing the domain model of the rule engine. The main functions and features of this module can include the following aspects:

[0062] Define the domain model: The domain model design module is responsible for defining the domain model required by the rule engine and clarifying the field attribute type information of the rule engine input. This model is closely related to the business logic. It describes the entities in the business and their relationships, ensuring that the rule engine can correctly understand and process business data.

[0063] Distinguish between embedded and external attributes: In the domain model, modules can distinguish between embedded and external attributes. This distinction enables the rule engine to clearly understand which attributes are part of the rule context and which are external inputs. In this way, the rule engine can effectively manage and operate data from different sources to ensure the accuracy and effectiveness of rule execution.

[0064] Design of behavioral logic: The domain model design module is not only responsible for defining the data structure, but also for designing and implementing different behavioral logics based on different attributes. This means that the model can flexibly adjust the logic of business rules according to changes in business requirements. By combining business logic with data models, developers can more efficiently implement complex business requirements.

[0065] Support for dynamic configuration of rules: The domain model design module enables the rule engine to support dynamic configuration of rules. This means that at runtime, the attributes and logic in the domain model can be updated according to specific business scenarios or conditions, so that the rule engine can flexibly respond to business changes and improve the adaptability and flexibility of the system.

[0066] Promote the reusability of rules: Through clear domain model design, developers can create reusable rules and logic components. This reusability not only improves development efficiency, but also reduces duplication of work and maintenance costs. Different business scenarios can share the same logic, thereby improving the efficiency and consistency of the overall system.

[0067] Synergy with rule collections: The domain model design module is closely integrated with other modules such as the rule collection configuration module and the rule executor. A clear domain model provides a clear context for the rule collection, so that the definition, execution and management of rules can be carried out within a unified framework. This collaboration improves the consistency and maintainability of the system.

[0068] Data validation and verification: The domain model design module can integrate data validation and verification mechanisms to ensure that the parameters passed in meet the expected format and type. This function enhances the robustness of the rule engine, prevents errors caused by data that does not meet expectations, and thus improves the stability of the system.

[0069] The domain model design module improves the flexibility, reusability and adaptability of the rule engine by defining and managing the domain model of the rule engine, distinguishing between embedded and external attributes, designing behavioral logic, and supporting dynamic configuration. The design of this module not only improves the efficiency and consistency of the overall system, but also provides a solid foundation for implementing complex business logic.

[0070] Rule execution reporting module 104:

[0071] The rule execution reporting module 104 is used to generate an execution report after each rule execution. The execution report includes the execution status, execution time, and all triggered rules and corresponding execution results.

[0072] In the rule engine, the rule execution report module is an important part of the general rule engine based on Spring's SpEL expression, responsible for generating a detailed execution report after each rule is executed. The main functions and features of this module include the following aspects:

[0073] Execution status recording: The rule execution report module can record the status of rule execution, including success, failure, and error information. This function enables developers and business personnel to quickly understand the results of rule execution, so as to determine whether the business logic is running as expected and take corresponding measures in a timely manner.

[0074] Execution time statistics: This module also records the time of each rule execution. This information is very important for performance analysis and optimization. Developers can identify possible performance bottlenecks by analyzing the execution time and then perform targeted optimization. This is crucial to ensure the stability and response speed of the rule engine in a high-concurrency environment.

[0075] Detailed information of triggered rules: In the rule execution report, the module lists all triggered rules and their corresponding execution results. This detailed information can help developers and business personnel understand which rules are activated, which actions are executed, and the impact of these actions on contextual data. This not only helps with debugging and troubleshooting, but also provides rich data support for subsequent business analysis.

[0076] Traceability and auditing capabilities: The rule execution reporting module provides traceability for the rule engine. All rule execution records can be archived for subsequent auditing and analysis. Enterprises can use these records to ensure compliance and quickly trace back to specific rule execution situations when problems arise, thereby improving the efficiency of problem solving.

[0077] Report format: This module can support execution report generation in multiple formats, such as text, JSON or XML.

[0078] Integration with business logic: The rule execution report module can be closely integrated with business logic, and developers can automatically trigger subsequent business operations based on the execution results. For example, when certain rules fail to execute, notifications can be automatically sent, logs can be recorded, or remedial measures can be executed. This automated processing improves the intelligence and responsiveness of the system.

[0079] User-defined report function: This module allows users to customize the content and format of execution reports according to their needs. Users can select specific fields, information, and structures to be recorded to better meet business needs. This flexibility enhances the user experience and makes the rule execution report module more practical.

[0080] Real-time monitoring and analysis: The rule execution report module can be integrated with the real-time monitoring system to provide real-time execution status and statistical data. This enables business managers to instantly understand the operating status of the rule engine, quickly respond to potential problems, and optimize business processes.

[0081] The rule execution report module enhances the transparency and manageability of the rule engine by recording execution status, counting execution time, listing trigger rule information, and providing traceability. The design of this module not only improves the maintainability and auditability of the system, but also provides important data support for business decision-making, helping enterprises make more accurate and timely judgments in complex business environments.

[0082] Engine execution result module 105:

[0083] The engine execution result module 105 is used to obtain the execution result according to the execution verification level of the control rule, and the execution result is the output basis of the rule engine.

[0084] In the rule engine, the engine execution result module is an important part of the general rule engine based on Spring's SpEL expression, responsible for obtaining the execution result according to the execution verification level of the control rule. The functions and features of this module include the following aspects:

[0085] Obtaining execution results: The engine execution results module can dynamically obtain the execution results of the rule engine based on the context and conditions of rule execution. These results can be Boolean values, numerical values, strings, etc., depending on the definition of the rule and business requirements. This flexibility enables the rule engine to adapt to a variety of business scenarios.

[0086] Verification level control: This module can determine the execution path of the rule and the result processing method according to different verification levels. By setting different verification levels, users can control the strictness and flexibility of execution. For example, for some important business logic, a higher verification level can be set to ensure the accuracy and reliability of the execution results.

[0087] Result feedback and response mechanism: The engine execution result module can feed back the execution results to the business logic layer to trigger corresponding follow-up operations. According to the execution results, the system can perform different business processes, such as discounts, order rejections, and notifications. This feedback mechanism ensures the automation and efficiency of the business process.

[0088] Real-time monitoring and analysis capabilities: This module can be integrated with the monitoring system to track the execution results of the rule engine in real time. This provides managers with important real-time data to help them identify potential problems in a timely manner and make corresponding adjustments and optimizations.

[0089] Scalability and customization: The engine execution result module allows users to customize the processing logic of the execution results according to specific needs. For example, different follow-up actions can be defined based on different execution results, which provides support for the diversification of business processes.

[0090] The engine execution result module enhances the flexibility and intelligence of the rule engine by dynamically obtaining execution results, controlling verification levels, implementing result feedback, and supporting complex logic. The design of this module not only improves the execution efficiency and accuracy of business logic, but also provides a solid guarantee for enterprises to respond promptly in a rapidly changing market environment.

[0091] Rule Factory Module 106:

[0092] The rule factory module 106 is used to load and manage rule sets, and to manage and control the creation and destruction of rule engines.

[0093] In the rule engine, the rule factory module is an important part of the general rule engine based on Spring's SpEL expression. It is responsible for unified loading and management of rule sets, as well as controlling the creation and destruction of the rule engine. The main functions and features of this module can be seen from the following aspects:

[0094] Loading and managing rule sets: The rule factory module is responsible for loading rule sets from the specified configuration source. These rule sets can be stored in different places, such as databases, XML files, or other configuration files. By centrally managing rule sets, the rule factory module ensures that all rules can be loaded and used effectively, thereby improving the maintainability and flexibility of the system.

[0095] Creation and destruction of rule engines: This module controls the life cycle of rule engines, including creation and destruction. This means that when the system needs to execute a rule, the rule factory module can quickly create a new rule engine instance and release resources in time after execution. This management method avoids waste of resources and improves system performance and efficiency.

[0096] Integration of rule factory and domain model: The rule factory module is closely integrated with the domain model design module. By utilizing the design of the domain model, the rule factory can ensure the consistency of rules and business logic when loading rule sets. This combination enables the definition and execution of rules to be carried out within a unified framework, enhancing the consistency of the system.

[0097] Support dynamic update of rules: The rule factory module supports dynamic update of rule sets, allowing users to add, modify or delete rules at runtime. This flexibility enables the system to quickly respond to changes in business needs and ensures that the rule engine can adapt to the ever-changing business environment.

[0098] Integration with rule context: The rule factory module works with the rule context module to ensure that context data is correctly passed and managed during rule execution. This integration enables the rule engine to refer to valid context information during execution, enhancing the accuracy of rule execution.

[0099] The rule factory module improves the flexibility, maintainability and performance of the rule engine by centrally managing rule sets, controlling the rule engine life cycle, supporting dynamic updates and closely integrating with other modules. The design of this module not only provides strong support for the implementation of business logic, but also provides enterprises with efficient business decision-making capabilities in a rapidly changing market environment.

[0100] Rule context module 107:

[0101] The rule context module 107 is used to store and transmit relevant data during the rule execution process.

[0102] Rule executor 108:

[0103] The rule executor 108 is used to call the execute method when receiving a business request, take the context of the incoming rule as a parameter, determine the rules that meet the execution conditions according to the rule conditions and the context, and execute the rule actions corresponding to the rules that meet the conditions in order of rule priority.

[0104] The rule executor uses the SpEL parser to parse and execute business rules based on the SpEL parser, and returns the execution results of the rules based on the SpEL parser, and the execution results include Boolean values, numerical values, and strings.

[0105] In a possible implementation, the rule executor supports parallel execution of multiple business rules.

[0106] In the rule engine, the rule executor is one of the core components of the general rule engine based on Spring's SpEL expression, responsible for actually executing the defined business rules. The functions and features of this module can include the following aspects:

[0107] Rule execution logic: The main responsibility of the rule executor is to execute the corresponding rules according to the predetermined logic based on the rule context and rule set passed in. This means that when receiving a business request, the rule executor will parse the rule conditions and determine which rules meet the execution conditions, thereby determining the subsequent operations.

[0108] Priority Processing When multiple rules may meet the conditions at the same time, the rule executor is responsible for executing the rule actions that meet the conditions in the order of rule priority. This priority processing mechanism ensures that important rules can be executed first in complex business scenarios, thereby improving the accuracy of decision-making.

[0109] Reference to data context: When executing rules, the rule executor will reference the passed-in rule context data and make judgments and operations based on the information in the context. This design ensures that rule execution can be based on the latest business data, making decisions more accurate and effective.

[0110] Result feedback and subsequent processing: After the rule executor completes the rule execution, it will generate the execution result and return it to the caller. Based on the execution result, the system can perform corresponding subsequent processing, such as triggering other business logic, updating database status, or sending notifications. This result feedback mechanism provides support for the automation of business processes.

[0111] The rule executor improves the flexibility and accuracy of the rule engine by executing business rules, handling priorities, integrating with the SpEL parser, referencing context data, feeding back execution results, and supporting exception handling. The design of this module not only provides strong support for the implementation of business logic, but also provides a solid foundation for enterprises to make timely and effective decisions in a rapidly changing market environment.

[0112] Dynamic rule adding module 109:

[0113] The dynamic rule adding module 109 is used to support dynamic addition of new business rules when the program is running.

[0114] The general rule engine based on Spring's SpEL expression proposed in this application, compared with the prior art, this application takes advantage of the Spring framework to achieve concise definition and efficient execution of rules. Compared with the existing rule engines based on XML or specific rule languages, this application allows developers to use SpEL (Spring Expression Language) expressions to directly define rules. SpEL is a powerful expression language that supports operations on Java objects, making the writing of rules more intuitive and flexible. Developers do not need to learn new rule languages ​​or formats, which reduces learning costs and development thresholds and improves development efficiency. Many existing rule engines cannot flexibly add new rules at runtime, and usually require recompilation or restarting the system. Through the dynamic rule addition module of this application, users can add, modify or delete rules at any time according to actual needs when the program is running. This flexibility enables the system to respond quickly to business changes, support rapid iteration and continuous delivery, and meet the requirements of agility and adaptability in modern software development. The rule set management module of this application provides a more systematic rule management mechanism. By effectively managing the life cycle (creation, update and deletion) of the rule set, developers can more easily maintain and organize rules. This not only improves the manageability of the rules, but also reduces potential errors caused by redundant or outdated rules, ensuring the clarity and consistency of business logic. The domain model design module of this application enables the rule engine to better adapt to the needs of different business fields. By clearly distinguishing between embedded attributes and external attributes, users can design corresponding rule logic according to specific business scenarios. This flexible design ensures the scalability of the rule engine, enabling it to be widely used in various industries and scenarios. The introduction of the rule execution report module enhances the transparency and traceability of the rule execution process. The execution report generated after each rule execution records in detail the execution status, execution time, triggered rules and corresponding execution results. This provides important data support for subsequent auditing, analysis and optimization, making business decisions more scientific and reasonable. Through the engine execution result module, the rule engine can obtain the execution results according to the execution verification level of the control rule. This design not only improves the execution efficiency of the rules, but also provides users with more accurate feedback to help them adjust and optimize business strategies in a timely manner. The general rule engine based on Spring's SpEL expression in this application is significantly better than the prior art in the efficiency of rule definition.

[0115] It is understandable that the method provided in the present application can be applied to a processing device, which is a processing device that can run a rule engine, such as a terminal device or a server that can run a rule engine. The method provided in the present application can be executed independently by a terminal device or a server, or it can be applied to a network scenario in which a terminal device and a server communicate, and is executed by the cooperation of a terminal device and a server. Among them, the terminal device can be a computer, a mobile phone and other devices. The server can be understood as an application server or a Web server. In actual deployment, the server can be a stand-alone server or a cluster server.

[0116] Figure 2 A flowchart of a rule engine application method provided in the present application, the method comprising the following steps:

[0117] S201: Define the rule set, rule executor and rule context in the Spring configuration file through the rule set configuration module.

[0118] The processing device defines the rule set, rule executor and rule context through the rule set configuration module in the Spring configuration file. The rule set is configured through SpEL expressions. The rule executor is used to process business requests, and the rule context is used to store data related to the current business.

[0119] In the rule engine, rule collection, rule executor and rule context are the core components of the rule engine. The first step of this method is to define these components in the Spring configuration file. This step initializes the configuration of the rule engine and lays the foundation for subsequent business logic processing.

[0120] S202: When receiving a service request, the service application sends a rule execution request to the rule executor. The rule execution request includes a rule identifier, parameters, and context information.

[0121] When the processing device receives the service request, the service application sends a rule execution request to the rule executor, where the rule execution request includes the identifier, parameters and context information of the rule.

[0122] S203: The rule executor loads the corresponding business rule from the rule repository according to the rule identifier in the request. If the rule is not found in the rule repository, the rule executor dynamically loads the business rule from an external resource and updates the rule repository.

[0123] External resources can be business rules in text form, business rules in script form, or of course any business rules.

[0124] S204: After the loading is completed, the rule executor creates an instance of the rule context and sets the data in the business request as attributes of the context.

[0125] After the processing device is loaded, the rule executor creates an instance of the rule context and sets the data in the business request as the attributes of the context.

[0126] S205: Execute the rule action corresponding to the rule based on the rule executor, and output the execution result based on the rule execution report module and the engine execution result module.

[0127] The processing device executes a rule action corresponding to the rule based on the rule executor, and outputs an execution result based on the rule execution report module and the engine execution result module.

[0128] This method allows dynamic loading and updating of business rules, which means that the system can quickly respond to changes in business requirements. In the prior art, many rule engines need to be restarted or redeployed to update rules. The dynamic loading mechanism provided by this method greatly improves the flexibility and adaptability of the system. This method makes the maintenance and update of rules simpler by centrally defining rule sets, rule executors, and rule contexts in the Spring configuration file, reduces management complexity, and improves maintainability. This method stores data related to the current business through the rule context module, so that rule execution can be based on the latest context information. This design improves the accuracy and intelligence of decision-making, and is more advantageous than the static data processing commonly used in traditional methods. By providing a unified interface and modular design, this method reduces the learning curve and implementation difficulty of developers. Developers can quickly get started and implement complex business logic, greatly improving development efficiency.

[0129] An embodiment of the present application also provides an application device of a rule engine, wherein the device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device performs the steps of the application method of the rule engine described in any embodiment of the present application.

[0130] In practical applications, the computer-readable storage medium may be any combination of one or more computer-readable media, which may be a computer-readable signal medium or a computer-readable storage medium.

[0131] The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.

[0132] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0133] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0134] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0135] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely schematic, in which the unit described as a separate component may or may not be physically separated, and the component prompted as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0136] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A rule engine, characterized in that: include: A rule set configuration module is used to configure a rule set defined by a SpEL expression in a Spring configuration file or program, where each rule set contains one or more rules, each of which includes a rule name, a rule condition, a rule action, and a rule priority, and the rule condition is defined by a SpEL expression; A rule set management module, used to manage the life cycle of multiple rule sets, which life cycle includes creating, updating and deleting rule sets; The domain model design module is used to design the domain model of the rule engine. The domain model is used to determine the field attribute type information of the rule engine input parameter. The domain model is used to distinguish between embedded attributes and external attributes, and to design and implement different behavior logics according to different attributes. A rule execution report module is used to generate an execution report after each rule is executed. The execution report includes the execution status, execution time, and all triggered rules and corresponding execution results; An engine execution result module, used to obtain an execution result according to the execution verification level of the control rule, and the execution result is the output basis of the rule engine; The rule factory module is used to load and manage rule sets, as well as manage and control the creation and destruction of rule engines; The rule context module is used to store and transmit relevant data during the rule execution process; The rule executor is used to call the execute method when receiving a business request, take the context of the passed-in rule as a parameter, determine the rules that meet the execution conditions according to the rule conditions and the context, and execute the rule actions corresponding to the rules that meet the conditions in order of rule priority; The dynamic rule adding module is used to support the dynamic addition of new business rules when the program is running.

2. The rule engine according to claim 1, characterized in that: The rule executor uses a SpEL parser to parse and execute business rules based on the SpEL parser, and returns an execution result of the rule based on the SpEL parser, wherein the execution result includes a Boolean value, a numerical value, and a string.

3. The rule engine according to claim 1, characterized in that: The rule executor supports the parallel execution of multiple business rules.

4. A method for applying a rule engine, characterized in that: include: In the Spring configuration file, a rule set, a rule executor and a rule context are defined through a rule set configuration module. The rule set is configured through a SpEL expression, the rule executor is used to process business requests, and the rule context is used to store data related to the current business; When receiving a business request, the business application sends a rule execution request to the rule executor, wherein the rule execution request includes a rule identifier, parameters and context information; The rule executor loads the corresponding business rule from the rule repository according to the rule identifier in the request. If the rule is not found in the rule repository, the rule executor dynamically loads the business rule from an external resource and updates the rule repository. After the loading is completed, the rule executor creates an instance of the rule context and sets the data in the business request as attributes of the context; The rule executor executes the rule action corresponding to the rule, and outputs the execution result based on the rule execution report module and the engine execution result module.

5. The method according to claim 4, characterized in that The rule action corresponding to the rule executed by the rule executor includes: Determine the rules that meet the execution conditions according to the rule conditions in the rule set and the data in the context, and the determination is based on the calculation result of the SpEL expression; For rules that meet the execution conditions, the rule executor executes rule actions in order of rule priority, and the rule actions can modify data in the rule context or generate output results.

6. The method according to claim 4, characterized in that The method further comprises: If an exception occurs during the execution of a rule, the rule executor automatically triggers the exception handling mechanism, performs a rollback operation, and generates a corresponding error report.

7. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the application method of the rule engine as described in any one of claims 4 to 6.

8. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the application method of the rule engine as described in any one of claims 4 to 6 is implemented.

Citation Information

Cited By

  • Method and device for intelligently examining key point service

    CN119849479A