Data processing method and device, equipment and computer readable storage medium
By obtaining rule engine objects and dividing rule files into small-scale executable objects, the problem of reduced maintainability of XML files is solved, and the stability and efficiency of rule execution are improved.
Patent Information
- Application Number
- CN202311425288.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-30
- Publication Date
- 2025-05-02
AI Technical Summary
As the number of rules increases, the maintainability of XML files decreases dramatically, resulting in unstable and inefficient rules execution.
Get the rule engine object through the rule name, and divide the overall rule file into multiple small-scale executable objects, reducing the waiting time for rule file parsing and improving the efficiency and stability of rule execution.
Improve the stability and efficiency of the execution of rules, and avoid the reduction of file maintainability due to the large overall rule scale.
Smart Images

Figure CN119917458A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data processing method and device, an electronic device, and a computer-readable storage medium. Background Art
[0002] In the related art, it is often necessary to use predefined rules to filter data that meets the requirements or perform certain specific processing on the data. These predefined rules can be executed by a rule engine. When the rule engine determines that certain data meets a certain rule, the action corresponding to the rule is executed for the data. At present, all rules are concentrated in one file. For example, all rules are concentrated in an eXtensible Markup Language (XML) file. As the number of rules increases, the maintainability of the file decreases sharply, which may lead to unstable rule execution. Moreover, it takes a long time to parse large-scale files, resulting in low efficiency in rule execution. Summary of the invention
[0003] The present application provides a data processing method and device, an electronic device, and a computer-readable storage medium, which can improve the execution efficiency and execution stability of rules.
[0004] In a first aspect, the present application provides a data processing method, which includes: in response to a rule execution request, determining the rule name and rule parameters of the rule execution request; obtaining a rule engine object corresponding to the rule name; based on the target rule of the rule engine object, processing the rule parameters to obtain a rule execution result corresponding to the rule parameters.
[0005] In the second aspect, the present application provides a data processing device, which includes: a data acquisition module, used to determine the rule name and rule parameters of the rule execution request in response to the rule execution request; an object acquisition module, used to obtain a rule engine object corresponding to the rule name; and an execution module, used to process the rule parameters based on the target rule of the rule engine object to obtain a rule execution result corresponding to the rule parameters.
[0006] In a third aspect, the present application provides a data processing system, which includes: at least one client and a server; the client is used to send a rule execution request to the server; the server is used to execute the data processing method described in any one of the embodiments of the present application.
[0007] In a fourth aspect, the present application provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can perform the above-mentioned data processing method.
[0008] In a fifth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned data processing method when executed by a processor / processing core.
[0009] The embodiment provided by the present application determines, in response to a rule execution request, the rule name and rule parameters of the rule execution request. The rule name can be used to clarify the rule to be used, which provides a basis for the subsequent acquisition of the rule engine object. The rule parameters can be used to determine the parameters to be used in the rule execution process; the rule engine object corresponding to the rule name is obtained, wherein the rule engine object can be an object obtained by formally converting and instantiating the rule script. On the one hand, the rule engine object is only an instantiation object of part of the rules. In this way, the overall rule file can be divided into multiple smaller executable objects, which improves the execution stability of the rules and avoids the reduction of file maintainability due to the large scale of the overall rules. In addition, the rule engine can execute the corresponding rules through the rule engine object, which reduces the waiting time consumed for parsing the rule file and improves the rule execution efficiency; based on the target rule of the rule engine object, the rule parameters are processed to obtain the rule execution result corresponding to the rule parameters.
[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings are used to provide a further understanding of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings. In the accompanying drawings:
[0012] Figure 1 A flowchart of a data processing method provided in an embodiment of the present application;
[0013] Figure 2 A schematic diagram of a rule tree provided in an embodiment of the present application;
[0014] Figure 3 A schematic diagram of a data processing method provided in an embodiment of the present application;
[0015] Figure 4 A flowchart of a data processing method provided in an embodiment of the present application;
[0016] Figure 5 A schematic diagram of a data processing method provided in an embodiment of the present application;
[0017] Figure 6 A block diagram of a data processing device provided in an embodiment of the present application;
[0018] Figure 7 A block diagram of a data processing system provided in an embodiment of the present application;
[0019] Figure 8 A block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the technical solution of the present application, the exemplary embodiments of the present application are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0021] In the absence of conflict, the embodiments of the present application and the features therein may be combined with each other.
[0022] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0023] The terms used herein are only used to describe specific embodiments and are not intended to limit the present application. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect.
[0024] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this application, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined herein.
[0025] In the related art, the rule engine usually executes rule processing based on the rule file in XML format. In the initialization phase, the rule engine loads and reads the rules in the XML file and converts them into executable rule instructions; during the execution process, the rule engine receives the http request sent by the client, takes the data carried in the http request as input parameters, executes the rules according to the corresponding rule instructions, and feeds back the execution results to the client. As the number of rules increases, the maintainability of the XML file decreases sharply, which may lead to unstable rule execution. Moreover, it takes a long time to parse large-scale XML files, resulting in inefficient rule execution.
[0026] In view of this, embodiments of the present application provide a data processing method and device, an electronic device, and a computer-readable storage medium.
[0027] In an embodiment of the present application, in response to a rule execution request, the rule name and rule parameters of the rule execution request are determined. The rule name can be used to clarify the rule to be used, which provides a basis for the subsequent acquisition of the rule engine object. The rule parameters can be used to determine the parameters to be used in the rule execution process; the rule engine object corresponding to the rule name is obtained, wherein the rule engine object can be an object obtained by formally converting and instantiating the rule script. On the one hand, the rule engine object is only an instantiation object of part of the rules. In this way, the overall rule file can be divided into multiple smaller executable objects, which improves the execution stability of the rules and avoids the reduction of file maintainability due to the large scale of the overall rules. In addition, the rule engine can execute the corresponding rules through the rule engine object, reducing the waiting time consumed for parsing the rule file and improving the rule execution efficiency; based on the target rule of the rule engine object, the rule parameters are processed to obtain the rule execution result corresponding to the rule parameters.
[0028] The data processing method according to the embodiment of the present application can be executed by an electronic device such as a terminal device or a server, and the terminal device can be a user equipment (UE), a mobile device, a user terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. The server can be an independent physical server, a server cluster composed of multiple servers, or a cloud server capable of cloud computing.
[0029] In a first aspect, an embodiment of the present application provides a data processing method.
[0030] Figure 1 A flowchart of a data processing method provided in an embodiment of the present application. Figure 1 , the method comprises the following steps.
[0031] Step S11, in response to the rule execution request, determining the rule name and rule parameters of the rule execution request.
[0032] In some optional implementations, the rule execution request is a request for requesting the rule engine to execute a corresponding rule. The rule may be a business rule, and each rule includes at least a condition for triggering the rule and a corresponding operation. For example, a rule may be characterized as follows: IF condition A THEN operation B, which means that operation B is executed when condition A is met.
[0033] It should be noted that the rules in the embodiments of the present application can perform technical processing on various types of technical data, where the technical data includes parameters with different technical connotations and different data forms, and the technical processing includes variable assignment, data storage, data calculation, data deletion, etc. The embodiments of the present application do not limit this.
[0034] In some optional implementations, in order to clarify the rules to be executed and the parameters to be used during the execution process, the rule name and rule parameters can be carried in the rule execution request, and the rule name and rule parameters in the rule execution request can be determined by parsing the rule execution request, etc. Among them, the rule parameters can be used to determine whether the conditions in the rule are met.
[0035] In some optional implementations, the rule execution request may be a request sent by a client, and correspondingly, the response to the rule execution request may be a server or a rule engine in the server receiving the rule execution request sent by the client. The rule execution request may be a Json format string jsonString, and the rule name and rule parameters may be obtained by parsing the jsonString.
[0036] It should be noted that if the obtained rule parameters are incomplete, or the obtained rule parameters only include key information (key) without corresponding value information (value), the missing part of the rule parameters can be further obtained from the database to obtain complete and accurate rule parameters.
[0037] In some optional implementations, in response to a rule execution request, before determining a rule name and rule parameters of the rule execution request, the method further includes: pushing the received rule execution request to a first message queue, the first message queue being used to store the rule execution request to be consumed. The rule engine consumes the rule execution request from the first message queue in sequence, which can improve processing efficiency and throughput.
[0038] Step S12, obtaining a rule engine object corresponding to the rule name.
[0039] In some optional implementations, the rule engine object is an object obtained by formally converting and instantiating the rule script, and the rule engine object includes at least one target rule. In other words, the rule engine object is an object that can be executed by the rule engine, which encapsulates one or more target rules. In this way, the rule engine object corresponding to the rule name can be determined based on the rule name, and the rule engine object can be executed by the rule engine, without parsing the entire rule file, and generating and executing the corresponding rule instructions based on the parsing results, thereby simplifying the rule execution process, avoiding the concentration of all rules in one file, and improving the stability and maintainability of the rule file.
[0040] In some optional implementations, obtaining a rule engine object corresponding to a rule name includes: obtaining a rule engine object corresponding to the rule name from a context cache of the rule engine according to the rule name. The context cache is some frequently used data or historical data (e.g., rule engine objects) cached in the context of the rule engine, so that these data can be obtained conveniently and efficiently when needed.
[0041] In some optional implementations, it is necessary to store some rule engine objects in the context cache of the rule engine in advance for backup.
[0042] In some optional implementations, before obtaining a rule engine object corresponding to the rule name from the context cache of the rule engine according to the rule name, the method further includes: obtaining an initial rule script, the initial rule script including the script code of at least one rule; performing form conversion and instantiation processing on the initial rule script to obtain a first rule engine object; and storing the first rule engine object in the context cache of the rule engine. The number of the first rule engine object may be one or more, which is not limited in the embodiment of the present application.
[0043] Exemplarily, the initial rule script can be regarded as a rule set in code form, which can be a script determined based on rules, rule groups, rule sets, and rule flows, and the embodiments of the present application do not limit this. Rule groups (CaseGroup), rule sets (Ruleset) and rule flows (RuleFlow) can all be regarded as a collection of rules, and the difference is that the respective granularities are different. For example, a rule group can include multiple similar rules, a rule set can include multiple rule groups, and a rule flow can include multiple rule sets. In addition, the number of initial rule scripts can be one or more, and each rule script includes corresponding script code, and the script code can correspond to one or more rules, and the embodiments of the present application do not limit this.
[0044] It can be seen that in the initialization phase, the initial rule script can be used to obtain the corresponding first rule engine object through form conversion and instantiation processing, and the first rule engine object is stored in the context cache of the rule engine for standby use.
[0045] In some optional implementations, considering that there may be a situation where the context cache does not store the rule engine object to be currently used (that is, the first rule engine object does not include the rule engine object to be currently used), the rule engine object stored in the context cache can be updated as needed to meet the rule execution requirements as much as possible.
[0046] In some optional implementations, the method further includes: if the first rule engine object does not match the rule name, obtaining a new rule script; performing form conversion and instantiation processing on the new rule script to obtain a second rule engine object that matches the rule name.
[0047] In other words, when there is no rule engine object matching the rule name in the context cache of the rule engine, a new rule script is obtained; the new rule script is converted and instantiated to obtain at least one second rule engine object; and based on the at least one second rule engine object, a second rule engine object corresponding to the rule name is obtained. The new rule script is relative to the initial rule script, and the rules corresponding to the new rule script are the rules that are not in the initial rule script, so as to achieve the purpose of generating a new rule engine object.
[0048] In some optional implementations, after obtaining the second rule engine object, the second rule engine object can also be stored in the context cache for standby use. At this time, the context cache includes both the first rule engine object and the second rule engine object, so that the data in the context cache is more comprehensive and can cover a wider range of rule processing scenarios.
[0049] From this, we can see that even if the context cache does not store the rule engine object to be used during the initialization phase, the new rule script can be converted and instantiated to obtain a new rule engine object, which can be stored in the context cache for backup, thereby updating the rule engine object in the context cache.
[0050] In some optional implementations, the initial rule script is converted and instantiated to obtain the first rule engine object, which may include the following steps: according to the initial rule script, determine the rule node corresponding to the initial rule script and the information of the rule node; according to the information of the rule node, build a rule tree corresponding to the initial rule script based on the rule node; convert the rule tree into a rule engine class code that conforms to a preset code format; instantiate the rule engine class code at least once to obtain the first rule engine object. Wherein, the rule node corresponds to any one of a rule condition, a rule operation, a rule group, a rule set and a rule flow, the rule condition refers to the condition in the rule, and the rule operation refers to the operation to be performed when the rule condition is met.
[0051] It should be noted that the process of determining the second rule engine object based on the new rules is similar to the above process, and exemplarily may include the following steps: according to the new rule script, determine the rule nodes and rule node information corresponding to the new rule script; according to the rule node information, construct a rule tree corresponding to the new rule script based on the rule nodes; convert the rule tree into a rule engine class code that conforms to a preset code format; instantiate the rule engine class code at least once to obtain a second rule engine object.
[0052] Exemplarily, the preset code format includes an object-oriented code format. For example, the preset code format may be a code format that complies with Java syntax, wherein Java is an object-oriented programming language. Accordingly, instantiation refers to the process of creating an object based on a class, specifically, the process of creating a rule engine object based on a rule engine class.
[0053] It can be seen that when generating the first rule engine object, it is first necessary to determine the rule nodes and their information according to the initial rule script, convert the rule nodes and their information into the form of a rule tree, and convert the rule tree into a rule engine class code in code form. After instantiating the rule engine class code, the corresponding first rule engine object can be obtained. The generation process of the second rule engine object is similar to this, and will not be described in detail here.
[0054] In some optional implementations, the information of the rule node includes the attribute information of the rule node and the level information of the rule node; accordingly, according to the initial rule script, determining the rule node corresponding to the initial rule script and the information of the rule node includes: traversing the initial rule script, identifying the rule nodes in the initial rule script and the association relationship between the rule nodes; according to the association relationship between the rule nodes, determining the attribute information of the rule node and the level information of the rule node. Among them, the association relationship between the rule nodes may include whether the rule nodes belong to the same rule script, condition group, and other attribution relationships, and the level information of the rule node may represent the node level of the rule node in the rule tree.
[0055] In some optional implementations, if the initial rule script is as follows:
[0056]
[0057] It can be seen that the initial rule script includes a general rule ruleA, and ruleA includes a rule group CaseGroup and three rules, and the rule group includes two rules. According to the initial rule script, we can get Figure 2 The rule tree shown.
[0058] Figure 2 A schematic diagram of a rule tree provided in an embodiment of the present application. Figure 2 The root node of the rule tree is rule node RA, which corresponds to the total rule ruleA in the initial rule script. There are 4 rule nodes set at the next level of the root node, among which rule node CG corresponds to rule group CaseGroup, rule node C3 corresponds to the rule condition of the first rule of ruleA, rule node C4 corresponds to the rule condition of the second rule of ruleA, and rule node C5 corresponds to the rule condition of the third rule of ruleA.
[0059] For rule node CG, two rule nodes are set at the next level, where rule node C1 corresponds to the rule condition of the first rule in condition group CaseGroup, and rule node C2 corresponds to the rule condition of the second rule in condition group CaseGroup. In addition, for rule node C1, a rule node S1 is set at the next level, which is used to indicate the operation to be performed when the rule condition corresponding to rule node C1 is met, which means that if customer.label = "HIGHT_RISK", Set(out.taskType, "manual") is executed; in addition, rule node S2 is set at the next level of rule node C2, which means that when the rule condition corresponding to rule node C2, customer.label = "LOW_RISK", Set(out.taskType, "sms") is executed.
[0060] Similarly, a rule node S3 is set at the next level of the rule node C3. The rule node S3 is used to indicate the operation to be performed when the rule condition corresponding to the rule node C3 is met. Here, it indicates that if customer.dpd>3and customer.dpd<=7, then execute Set(out.randomRate, funcRandomRate()).
[0061] A rule node S4 is set at the next level of rule node C4, and the rule node S4 is used to indicate that the operation Set(out.callGroup, "ABTestG2") should be executed when the rule condition out.randomRate>50 corresponding to rule node C4 is met; a rule node S5 is set at the next level of rule node C5, and the rule node S5 is used to indicate that the operation Set(out.callGroup, "ABTestG2") should be executed when the rule condition out.randomRate<=50 corresponding to rule node C5 is met.
[0062] Furthermore, for the rule tree, starting from the root node, from left to right, all rule nodes are traversed from shallow to deep according to the hierarchy until the leaf node, and the corresponding Java code is generated according to the rule nodes. Each Rule, CaseGroup, Ruleset, and RuleFlow corresponds to a Java method, and these methods eventually form a rule engine class code RuleExec.java.
[0063] based on Figure 2 The rule engine class code generated by the rule tree shown is as follows:
[0064]
[0065]
[0066] By instantiating the above rule engine code, a corresponding first rule engine object can be obtained.
[0067] It should be noted that, from the above content, it can be seen that when the conditions in the rules are met, the operations performed include determining the task type, using preset functions to perform some data calculations, and storing some data in memory, etc. The above operations are all technical operations, which require the support of the computing power resources, storage resources and communication resources of the electronic device, and may affect the allocation method and overhead of various resources by the electronic device.
[0068] Step S13, based on the target rule of the rule engine object, the rule parameters are processed to obtain the rule execution results corresponding to the rule parameters.
[0069] In some optional implementations, the target rule includes conditions and operations, and the rule parameters can be regarded as the input data of the rule. The rule parameters are used to determine whether the conditions of the rule are met. If it is determined that the conditions are met, the corresponding operation is performed. Otherwise, if it is determined that the conditions are not met, the corresponding operation is not performed.
[0070] Exemplarily, the rule engine object includes a target rule: Case(customer.label="HIGHT_RISK"), Set(out.taskType, "manual"), and the rule parameters include "customer.label: HIGHT_RISK". The conditions that satisfy the target rule can be determined through the rule parameters. Therefore, the corresponding operation is performed and the value key of the task type taskType is stored as "manual".
[0071] In some optional implementations, in addition to using rule parameters, data can also be interacted with some business systems as needed to obtain some intermediate data or transmit some intermediate data to the business system, thereby improving the flexibility of data interaction. In addition, since the above interaction process belongs to the call of the internal method of the Java Virtual Machine (JVM), the execution efficiency is relatively high.
[0072] In some optional implementations, the target rule includes a first rule and a second rule; accordingly, based on the target rule of the rule engine object, the rule parameters are processed to obtain a rule execution result corresponding to the rule parameters, including: based on the first rule, the rule parameters are processed to obtain an intermediate result; based on the second rule, a preset custom function is called to interact with the target business system for data to obtain an interaction result; based on the intermediate result and the interaction result, a rule execution result corresponding to the rule parameters is obtained.
[0073] Among them, the custom function is a function that can realize specific functions according to business needs, and some business-related and relatively independent functions can be encapsulated as custom functions. Since the embodiment of the present application supports custom functions, the rule engine can seamlessly link various business systems, and the flexibility of data interaction and processing is high.
[0074] In some optional implementations, some prefabricated functions can be pre-set for use by the rule engine. When the prefabricated functions do not meet the business scenarios, new development functions are supported. The new functions are custom functions.
[0075] For example, the custom function includes a phone state determination function, through which it can be determined whether the phone is in a suspended state.
[0076] In summary, in the process of executing the rule engine object, some target rules can be used to process the rule parameters accordingly to obtain some intermediate results. At the same time, based on other target rules, custom functions can be called to interact with some target business systems to obtain some interaction results. Based on the intermediate results and interaction results obtained, the final rule execution results can be obtained.
[0077] In some optional implementations, after processing the rule parameters based on the target rule of the rule engine object and obtaining the rule execution result corresponding to the rule parameters, the method further includes: pushing the rule execution result to the second message queue. In this way, the client can consume the rule execution results from the second message queue in sequence, thereby improving processing efficiency and throughput.
[0078] In an embodiment of the present application, in response to a rule execution request, the rule name and rule parameters of the rule execution request are determined. The rule name can be used to clarify the rule to be used, which provides a basis for the subsequent acquisition of the rule engine object. The rule parameters can be used to determine the parameters to be used in the rule execution process; the rule engine object corresponding to the rule name is obtained, wherein the rule engine object can be an object obtained by formally converting and instantiating the rule script. On the one hand, the rule engine object is only an instantiation object of part of the rules. In this way, the overall rule file can be divided into multiple smaller executable objects, which improves the execution stability of the rules and avoids the reduction of file maintainability due to the large scale of the overall rules. In addition, the rule engine can execute the corresponding rules through the rule engine object, reducing the waiting time consumed for parsing the rule file and improving the rule execution efficiency; based on the target rule of the rule engine object, the rule parameters are processed to obtain the rule execution result corresponding to the rule parameters.
[0079] Figure 3 A schematic diagram of a data processing method provided in an embodiment of the present application. Figure 3 , client 1, client 2, ..., client n (n≥1) can send rule execution requests to the rule engine. In order to improve data throughput and request execution efficiency, the rule execution requests sent by the above clients are pushed to the first message queue for consumption by the rule engine.
[0080] For the rule engine, it can load the rule script through the data loading function, parse and convert the rule script, and obtain the rule engine class code. Furthermore, the rule engine class code can be compiled and syntax checked, and instantiated after passing the syntax check to obtain the rule engine object, and the rule engine object is cached in the context cache of the rule engine for standby.
[0081] In some optional implementations, after the rule engine consumes a rule execution request from the first message queue, it determines the rule name and rule parameters in the rule execution request, and obtains the rule engine object corresponding to the rule name from the context cache, wherein the rule engine object includes at least one target rule, and each target rule includes corresponding conditions and operations. Then, for each target rule, the corresponding rule parameters are used to determine whether the conditions of the target rule are met. If it is determined that the conditions are met, the corresponding operation is performed; otherwise, if it is determined that the conditions are not met, the corresponding operation is not performed. After completing the processing of all target rules, the final rule execution result can be obtained, and the rule execution result can be pushed to the second message queue. Client 1 to client n can consume the corresponding rule execution results from the second message queue.
[0082] In some optional implementations, if the rule parameters obtained by the rule engine from the rule execution request are missing, some data can be obtained from the database by data loading, merged with the rule parameters, and the merged result is used as input data for the rule engine to execute the rule.
[0083] In some optional implementations, during the rule execution process, the rule engine can interact with the business system through custom functions to send some intermediate data in the rule processing process to the business system, or obtain some interaction data from the business system, thereby improving the flexibility and efficiency of data interaction during the rule execution process.
[0084] Figure 4 A flowchart of a data processing method provided in an embodiment of the present application.
[0085] Step S401: The client sends a rule execution request to the rule engine through a message queue.
[0086] For example, the message queue may be a queue based on Kafka, where Kafka is a distributed stream processing platform.
[0087] Step S402: The rule engine parses the rule execution request to obtain the rule name and the first rule parameter.
[0088] Step S403: the rule engine obtains the second rule parameter from the database, and combines the first rule parameter and the second rule parameter into rule input data.
[0089] Step S404: the rule engine obtains the rule engine object corresponding to the rule name from the context cache.
[0090] In some optional implementations, the initialization process of the rule engine object includes the following steps: first, load and parse the initial rule script, convert the initial rule script into rule nodes, assemble the rule nodes into a rule tree with a tree structure, traverse the rule tree from the root node of the rule tree, and generate the rule code RuleExec.java; compile RuleExec.java into the rule engine class code RuleExec.class file through the Java compiler JavaCompiler, and instantiate the RuleExec.class file through Class.forName (find and load the specified class) to obtain the rule engine object, and put the rule execution object into the context cache.
[0091] Step S405: the rule engine calls the run method corresponding to the rule engine object, executes the rule engine object based on the rule input data, and obtains the rule execution result.
[0092] The run method is a method for running the rule engine object.
[0093] Step S406: store the rule execution result in the database, and feed back the rule execution result to the client through the message queue.
[0094] Figure 5 A schematic diagram of a data processing method provided in an embodiment of the present application. Figure 5 , the data processing process includes the following:
[0095] First, the external system (e.g., each client) sends a message carrying a rule execution request to the server through Kafka, and the server performs data merging based on the rule engine to obtain the input parameters of the rule engine. The exemplary processing process includes: receiving Kafka messages, reading database data, overwriting database data with Kafka messages, and merging data.
[0096] Secondly, the rule engine obtains the rule engine object based on the rule context (MSRuleContext). The exemplary processing process includes: loading scripts, parsing and converting, compiling and initializing, and caching initialization objects. Specifically, the initial rule script is loaded from the rule script file, the initial rule script is converted into rule nodes, and the rule nodes are assembled into a rule tree with a tree structure. The rule tree is traversed from the root node of the rule tree to generate rule code. The rule code is compiled into a rule engine class code file through a compiler, and the engine class code file is initialized and returned to the corresponding instance to obtain the initial rule engine object, and the rule execution object is placed in the rule context for caching. When necessary, the matching rule engine object is obtained from the context cache based on the rule name, the merged data obtained in the previous step is used as input data, and the run method of the rule engine object is called to execute the corresponding rule, thereby obtaining the rule execution result.
[0097] Finally, after obtaining the rule execution result, the corresponding processing process may include: sending the rule execution result to the outside through Kafka so that an external system (which may be the same as the external system that initially sent the rule execution request, or different, without limitation) receives the rule execution result, and updating the rule execution result to the database for standby.
[0098] It can be understood that the above-mentioned various method embodiments mentioned in this application can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, this application will not go into details. Those skilled in the art can understand that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined by its function and possible internal logic.
[0099] In a second aspect, an embodiment of the present application provides a data processing device.
[0100] Figure 6 A block diagram of a data processing device provided in an embodiment of the present application.
[0101] Reference Figure 6 , an embodiment of the present application provides a data processing device, and the data processing device 600 includes the following modules.
[0102] The data acquisition module 601 is used to determine the rule name and rule parameters of the rule execution request in response to the rule execution request.
[0103] The object obtaining module 602 is used to obtain the rule engine object corresponding to the rule name.
[0104] The execution module 603 is used to perform data processing on the rule parameters based on the target rule of the rule engine object to obtain the rule execution result corresponding to the rule parameters.
[0105] In some optional implementations, the rule engine object is an object obtained by converting and instantiating the rule script, and the number of target rules of the rule engine object can be one or more.
[0106] In some optional implementations, when the object obtaining module 602 obtains the rule engine object corresponding to the rule name, the following steps are performed:
[0107] According to the rule name, obtain the rule engine object corresponding to the rule name from the context cache of the rule engine.
[0108] In some optional implementations, before obtaining a rule engine object corresponding to the rule name from the context cache of the rule engine according to the rule name, the data processing device is also used to perform the following steps: obtaining an initial rule script; performing formal conversion and instantiation processing on the initial rule script to obtain a first rule engine object; and storing the first rule engine object in the context cache of the rule engine.
[0109] In some optional implementations, the data processing device is also used to perform the following steps: if the first rule engine object does not match the rule name, obtain a new rule script; convert and instantiate the new rule script to obtain a second rule engine object that matches the rule name.
[0110] In some optional implementations, the initial rule script is converted and instantiated to obtain a first rule engine object, including the following steps: according to the initial rule script, determining the rule node corresponding to the initial rule script and the information of the rule node; according to the information of the rule node, constructing a rule tree corresponding to the rule script based on the rule node; converting the rule tree into a rule engine class code that conforms to a preset code format; and instantiating the rule engine class code at least once to obtain the first rule engine object.
[0111] In some optional implementations, the information of the rule node includes the attribute information of the rule node and the level information of the rule node; accordingly, according to the initial rule script, the rule node corresponding to the initial rule script and the information of the rule node are determined, including: traversing the initial rule script, identifying the rule nodes in the initial rule script and the association relationship between the rule nodes; according to the association relationship between the rule nodes, determining the attribute information of the rule node and the level information of the rule node.
[0112] In some optional implementations, the target rule includes a first rule and a second rule; accordingly, when the execution module 603 processes the rule parameters based on the target rule of the rule engine object and obtains the rule execution result corresponding to the rule parameters, the following steps are performed: based on the first rule, the rule parameters are processed to obtain an intermediate result; based on the second rule, a preset custom function is called to interact with the target business system for data to obtain an interaction result; based on the intermediate result and the interaction result, a rule execution result corresponding to the rule parameters is obtained.
[0113] In some optional implementations, before responding to a rule execution request and determining the rule name and rule parameters, the data processing device is also used to perform the following steps: pushing the rule execution request to a first message queue, the first message queue being used to store the rule execution requests to be consumed; based on the target rule of the rule engine object, processing the rule parameters, and obtaining the rule execution result corresponding to the rule parameters, the method also includes: pushing the rule execution result to a second message queue.
[0114] In an embodiment of the present application, a data acquisition module is used to respond to a rule execution request and determine the rule name and rule parameters in the rule execution request. The rule name can be used to clarify the rule to be used, which provides a basis for the subsequent acquisition of the rule engine object. The rule parameters can be used to determine the parameters to be used in the rule execution process; the object acquisition module is used to obtain a rule engine object corresponding to the rule name, wherein the rule engine object can be an object obtained by formally converting and instantiating the rule script. On the one hand, the rule engine object is only an instantiated object of some rules. In this way, the overall rule file can be divided into multiple smaller executable objects, which improves the execution stability of the rules and avoids the reduction of file maintainability due to the large scale of the overall rules. In addition, the rule engine can execute the corresponding rules through the rule engine object, which reduces the waiting time consumed for parsing the rule file and improves the rule execution efficiency; the execution module is used to process the rule parameters based on the target rules of the rule engine object to obtain the rule execution results corresponding to the rule parameters.
[0115] In a third aspect, an embodiment of the present application provides a data processing system.
[0116] Figure 7 A block diagram of a data processing system provided in an embodiment of the present application.
[0117] Reference Figure 7 An embodiment of the present application provides a data processing system, which includes: at least one client 701 and a server 702; wherein the client 701 is used to send a rule execution request to the server 702; and the server 702 is used to execute any one of the data processing methods in the embodiments of the present application.
[0118] In addition, the present application also provides electronic devices and computer-readable storage media, which can be used to implement any data processing method provided in the present application. The corresponding technical solutions and descriptions are referred to in the corresponding records of the method part and will not be repeated here.
[0119] Each module in the above data processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0120] Figure 8 A block diagram of an electronic device provided in an embodiment of the present application.
[0121] Reference Figure 8An embodiment of the present application provides an electronic device, which includes: at least one processor 801; at least one memory 802, and one or more I / O interfaces 803, connected between the processor 801 and the memory 802; wherein the memory 802 stores one or more computer programs that can be executed by at least one processor 801, and the one or more computer programs are executed by at least one processor 801 so that the at least one processor 801 can execute the above-mentioned data processing method.
[0122] Each module in the above electronic device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0123] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the above-mentioned data processing method when executed by the processor / processing core. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.
[0124] An embodiment of the present application also provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above-mentioned data processing method.
[0125] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).
[0126] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.
[0127] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0128] The computer program instructions for performing the operation of the present application can be assembler instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on a user's computer, partially on a user's computer, executed as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer can 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 can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of a computer-readable program instruction to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA), the electronic circuit can execute a computer-readable program instruction, thereby realizing various aspects of the present application.
[0129] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0130] Various aspects of the present application are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0131] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0132] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0133] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can also be executed in the opposite order sometimes, depending on the function involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs the function or action of the specification, or can be realized by a combination of special-purpose hardware and computer instructions.
[0134] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present application as set forth in the appended claims.
Claims
1. A data processing method, characterized in that: The method comprises: In response to a rule execution request, determining a rule name and rule parameters of the rule execution request; Obtain a rule engine object corresponding to the rule name; Based on the target rule of the rule engine object, the rule parameters are processed to obtain a rule execution result corresponding to the rule parameters.
2. The method according to claim 1, characterized in that The obtaining of a rule engine object corresponding to the rule name includes: According to the rule name, a rule engine object corresponding to the rule name is obtained from a context cache of the rule engine.
3. The method according to claim 2, characterized in that Before obtaining the rule engine object corresponding to the rule name from the context cache of the rule engine according to the rule name, the method further includes: Get the initial rule script; Performing form conversion and instantiation processing on the initial rule script to obtain a first rule engine object; The first rule engine object is stored in a context cache of the rule engine.
4. The method according to claim 3, characterized in that The method further comprises: If the first rule engine object does not match the rule name, obtaining a new rule script; The new rule script is converted and instantiated to obtain a second rule engine object matching the rule name.
5. The method according to claim 3, characterized in that: The converting and instantiating the initial rule script to obtain a first rule engine object includes: According to the initial rule script, determine the rule node corresponding to the initial rule script and the information of the rule node; According to the information of the rule node, construct a rule tree corresponding to the initial rule script based on the rule node; Convert the rule tree into a rule engine class code that complies with a preset code format; The rule engine class code is instantiated at least once to obtain the first rule engine object.
6. The method according to claim 5, characterized in that The information of the rule node includes attribute information of the rule node and level information of the rule node; The step of determining, according to the initial rule script, a rule node corresponding to the initial rule script and information of the rule node includes: Traversing the initial rule script, identifying the rule nodes in the initial rule script and the association relationships between the rule nodes; According to the association relationship between the rule nodes, the attribute information of the rule nodes and the level information of the rule nodes are determined.
7. The method according to claim 1, characterized in that The target rule includes a first rule and a second rule; The target rule based on the rule engine object processes the rule parameter to obtain a rule execution result corresponding to the rule parameter, including: Based on the first rule, processing the rule parameter to obtain an intermediate result; Based on the second rule, calling a preset custom function to interact with the target business system to obtain an interaction result; A rule execution result corresponding to the rule parameter is obtained according to the intermediate result and the interaction result.
8. The method according to claim 1, characterized in that Before determining the rule name and rule parameters of the rule execution request in response to the rule execution request, the method further includes: Pushing the rule execution request to a first message queue, where the first message queue is used to store the rule execution request to be consumed; After the target rule based on the rule engine object processes the rule parameter to obtain a rule execution result corresponding to the rule parameter, the method further includes: The rule execution result is pushed to the second message queue.
9. A data processing device, characterized in that: The device comprises: A data acquisition module, configured to determine, in response to a rule execution request, a rule name and rule parameters of the rule execution request; An object acquisition module, used to acquire a rule engine object corresponding to the rule name; The execution module is used to process the rule parameters based on the target rule of the rule engine object to obtain a rule execution result corresponding to the rule parameters.
10. A data processing system, characterized in that: The data processing system includes: at least one client and a server; The client is used to send a rule execution request to the server; The server is used to execute the data processing method according to any one of claims 1 to 8.
11. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor to enable the at least one processor to perform the data processing method according to any one of claims 1 to 8.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the data processing method according to any one of claims 1 to 8.