Service processing method, device, equipment and storage medium based on strategy pattern

By adopting a service processing method based on policy mode in the microservice architecture, the return data of different services is parsed and processed, and the problem of inconsistent data formats and parameter names of different services is solved, and the effect of simplifying data processing and improving service processing efficiency is achieved.

CN111240690BActive Publication Date: 2025-03-28CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010032525.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-13
Publication Date
2025-03-28
Estimated Expiration
2040-01-13

AI Technical Summary

Technical Problem

In the microservice architecture, the return data format and parameter names of different services are inconsistent, which causes developers to need to process and parse frequently, generate a large amount of duplicate code, and reduce the efficiency of service processing.

Method used

The service processing method based on the policy mode is adopted. By receiving the target service instructions, analyzing and determining the target calling policy, obtaining the target result processor and parameter parser, and determining whether the processor is registered in the control inversion container. If registered, the parameter parser is called to process the data.

Benefits of technology

It avoids the generation of a large number of duplicate code, simplifies the data processing process, improves the processing efficiency of services, and adapts to changes in different service data formats.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111240690B_ABST
    Figure CN111240690B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of big data technology, and discloses a service processing method, device, equipment and storage medium based on a policy pattern, which is used to call a corresponding parameter parser for processing when the data format of the service changes, thereby simplifying the data processing process. The method of the present invention comprises: receiving a target service instruction sent by a terminal, the target service instruction is used to obtain target service data; parsing the target service instruction, and determining a target call strategy corresponding to the target service instruction; determining a target result processor according to the target call strategy, the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide target service data; judging whether the target result processor has been registered in a control inversion container; if the target result processor has been registered in the control inversion container, determining a target interface of a target parameter parser corresponding to the target result processor, and calling the target interface to access the target parameter parser.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data technology, and in particular to a service processing method, device, equipment and storage medium based on a strategy pattern. Background Art

[0002] With the promotion of microservice architecture, more and more companies are using microservices to build their own business platforms. Calls between different services are becoming more and more frequent. The input and output parameters of interface calls are usually in the form of JSON data format to meet the RESTful style. The content returned by the interface call mainly includes the code and message representing the call result, as well as the returned data data. However, the formats of the return data defined by different services are different. Not only the formats are different, the parameter names are also different, and the codes representing success are also different.

[0003] This brings up a problem. During the interface development process, every time a new interface is connected, developers need to pay attention to the data format and data parameters returned by the connected service. At the same time, there is a large amount of repeated code in the program to determine whether the interface returns successfully and parse the returned data.

[0004] In the existing solution, different services correspond to different data formats, which require corresponding codes for processing. The codes are lengthy and the service processing efficiency is low. Summary of the invention

[0005] The present invention provides a service processing method, apparatus, device and storage medium based on a policy pattern, which is used to call a corresponding parameter parser for processing when the data format of a service changes, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process and improving the processing efficiency of the service.

[0006] A first aspect of an embodiment of the present invention provides a service processing method based on a policy pattern, comprising: receiving a target service instruction sent by a terminal, the target service instruction being used to obtain target service data; parsing the target service instruction to determine a target call strategy corresponding to the target service instruction; determining a target result processor according to the target call strategy, the target result processor being used to index a target parameter parser, the target parameter parser being used to provide the target service data; determining whether the target result processor has completed registration in a control inversion container; if the target result processor has completed registration in the control inversion container, determining a target interface of the target parameter parser corresponding to the target result processor, and calling the target interface to access the target parameter parser.

[0007] Optionally, in a first implementation method of the first aspect of the embodiment of the present invention, the target service instruction is parsed to determine the target calling strategy corresponding to the target service instruction, including: parsing the return data field of the target service instruction to determine the name of the target service corresponding to the target service instruction; determining the target data format corresponding to the target service according to the name of the target service; determining a target calling strategy that matches the target data format in a preset calling strategy table, the target calling strategy having a corresponding target result processor, and the target result processor is used to obtain service content corresponding to the target service, and the service content has the target data format.

[0008] Optionally, in a second implementation method of the first aspect of the embodiment of the present invention, determining the target data format corresponding to the target service according to the name of the target service includes: if the name of the target service is to count the usage rate of physical memory, then determining that the target data format corresponding to the usage rate of physical memory is a percentage value; if the name of the target service is to count the response time of a microservice, then determining that the target data format corresponding to the response time of the microservice is a decimal value.

[0009] Optionally, in a third implementation method of the first aspect of the embodiment of the present invention, the target result processor is determined according to the target call strategy, the target result processor is used to index the target parameter parser, and the target parameter parser is used to provide the target service data, including: determining the target service parameter name corresponding to the target service according to the target call strategy; determining the name of the corresponding target parameter parser based on the target service parameter name, and the target parameter parser is used to provide the target service data; setting the name of the target parameter parser as the target index; generating a target result processor, and injecting the target index into the target result processor.

[0010] Optionally, in a fourth implementation manner of the first aspect of the embodiment of the present invention, after determining whether the target result processor has completed registration in the control inversion container, the method also includes: if the target result processor has not completed registration in the control inversion container, determining the corresponding target parameter parser according to the target call strategy; generating a target object corresponding to the target result processor according to a preset factory class and the target parameter parser; hosting the target object in the control inversion container; assigning a corresponding configuration file to the target object, and registering the target result processor in the control inversion container according to the configuration file.

[0011] Optionally, in a fifth implementation method of the first aspect of the embodiment of the present invention, determining the corresponding target parameter parser according to the target call strategy includes: determining the target service parameter name corresponding to the target service of the target service instruction according to the target call strategy; determining the corresponding target data format according to the target service parameter name; generating the corresponding target parameter parser and the name of the target parameter parser based on the target data format; setting the name of the target parameter parser as the target index; injecting the target index into the target parameter parser through a preset constructor or a preset assignment function; and determining an interface of the target parameter parser, the interface being used to instruct the target parameter parser to obtain target service data in a target data format.

[0012] Optionally, in a sixth implementation manner of the first aspect of the embodiment of the present invention, the determination of whether the target result processor has completed registration in the control inversion container includes: obtaining a target identifier of the target result processor; reading a resource file of the control inversion container, the resource file including a registration identifier of a registered result processor; determining whether there is a registration identifier identical to the target identifier in the resource file; if there is a registration identifier identical to the target identifier in the resource file, determining that the target result processor has completed registration in the control inversion container; if there is no registration identifier identical to the target identifier in the resource file, determining that the target result processor has not completed registration in the control inversion container.

[0013] The second aspect of an embodiment of the present invention provides a service processing device based on a policy pattern, comprising: a receiving unit, used to receive a target service instruction sent by a terminal, the target service instruction being used to obtain target service data; a parsing unit, used to parse the target service instruction and determine a target call strategy corresponding to the target service instruction; a first determination unit, used to determine a target result processor according to the target call strategy, the target result processor being used to index a target parameter parser, and the target parameter parser being used to provide the target service data; a judging unit, used to judge whether the target result processor has completed registration in a control inversion container; a calling unit, if the target result processor has completed registration in the control inversion container, used to determine a target interface of the target parameter parser corresponding to the target result processor, and call the target interface to access the target parameter parser.

[0014] Optionally, in a first implementation method of the second aspect of the embodiment of the present invention, the parsing unit is specifically used for: a parsing module, used to parse the return data field of the target service instruction, and determine the name of the target service corresponding to the target service instruction; a data format module, used to determine the target data format corresponding to the target service according to the name of the target service; a policy determination module, used to determine a target call policy that matches the target data format in a preset call policy table, the target call policy having a corresponding target result processor, and the target result processor being used to obtain service content corresponding to the target service, and the service content has the target data format.

[0015] Optionally, in a second implementation method of the second aspect of the embodiment of the present invention, the data format module is specifically used to: if the name of the target service is to count the usage rate of physical memory, then determine that the target data format corresponding to the usage rate of physical memory is a percentage value; if the name of the target service is to count the response time of microservices, then determine that the target data format corresponding to the response time of the microservice is a decimal value.

[0016] Optionally, in a third implementation method of the second aspect of the embodiment of the present invention, the first determination unit is specifically used to: determine the target service parameter name corresponding to the target service according to the target call strategy; determine the name of the corresponding target parameter parser based on the target service parameter name, and the target parameter parser is used to provide target service data; set the name of the target parameter parser as the target index; generate a target result processor, and inject the target index into the target result processor.

[0017] Optionally, in a fourth implementation manner of the second aspect of the embodiment of the present invention, the service processing device based on the strategy pattern also includes: a second determination unit, used to determine the corresponding target parameter parser according to the target call strategy if the target result processor has not completed registration in the control inversion container; a generation unit, used to generate a target object corresponding to the target result processor according to a preset factory class and the target parameter parser; a hosting unit, used to host the target object in the control inversion container; an allocation registration unit, used to allocate a corresponding configuration file to the target object, and register the target result processor in the control inversion container according to the configuration file.

[0018] Optionally, in a fifth implementation manner of the second aspect of the embodiment of the present invention, the second determination unit specifically includes: a name determination module, used to determine the target service parameter name corresponding to the target service instruction according to the target call strategy; a format determination module, used to determine the corresponding target data format according to the target service parameter name; a generation module, used to generate a corresponding target parameter parser and the name of the target parameter parser based on the target data format; a setting module, used to set the name of the target parameter parser as a target index; an injection module, used to inject the target index into the target parameter parser through a preset constructor or a preset assignment function; an interface determination module, used to determine the interface of the target parameter parser, the interface being used to instruct the target parameter parser to obtain target service data in a target data format.

[0019] Optionally, in a sixth implementation manner of the second aspect of the embodiment of the present invention, the judgment unit is specifically used to: obtain a target identifier of the target result processor; read a resource file of the control inversion container, the resource file including a registration identifier of a registered result processor; judge whether there is a registration identifier identical to the target identifier in the resource file; if there is a registration identifier identical to the target identifier in the resource file, determine that the target result processor has completed registration in the control inversion container; if there is no registration identifier identical to the target identifier in the resource file, determine that the target result processor has not completed registration in the control inversion container.

[0020] The third aspect of an embodiment of the present invention provides a policy-based service processing device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the policy-based service processing method described in any of the above-mentioned embodiments when executing the computer program.

[0021] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the service processing method based on the policy pattern described in any of the above embodiments are implemented.

[0022] In the technical solution provided by the embodiment of the present invention, a target service instruction sent by a receiving terminal is used to obtain target service data; the target service instruction is parsed to determine the target call strategy corresponding to the target service instruction; a target result processor is determined according to the target call strategy, the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide target service data; it is determined whether the target result processor has completed registration in the control inversion container; if the target result processor has completed registration in the control inversion container, the target interface of the target parameter parser corresponding to the target result processor is determined, and the target interface is called to access the target parameter parser. In the embodiment of the present invention, when the data format of the service changes, the corresponding parameter parser is called for processing, which avoids the generation of a large amount of duplicate code, simplifies the data processing process, and improves the processing efficiency of the service. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 A schematic diagram of an embodiment of a service processing method based on a strategy pattern in an embodiment of the present invention;

[0024] Figure 2 It is a schematic diagram of another embodiment of the service processing method based on the strategy pattern in an embodiment of the present invention;

[0025] Figure 3 A schematic diagram of an embodiment of a service processing device based on a policy mode in an embodiment of the present invention;

[0026] Figure 4 It is a schematic diagram of another embodiment of a service processing device based on a policy mode in an embodiment of the present invention;

[0027] Figure 5 The figure is a schematic diagram of an embodiment of a service processing device based on a policy mode in an embodiment of the present invention. DETAILED DESCRIPTION

[0028] The present invention provides a service processing method, apparatus, device and storage medium based on a policy pattern, which is used to call a corresponding parameter parser for processing when the data format of a service changes, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process and improving the processing efficiency of the service.

[0029] In order to enable those skilled in the art to better understand the solutions of the present invention, the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0030] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0031] See also Figure 1 , a flow chart of a service processing method based on a policy pattern provided by an embodiment of the present invention, specifically comprising:

[0032] 101. Receive a target service instruction sent by a terminal, where the target service instruction is used to obtain target service data.

[0033] The server receives the target service instruction sent by the terminal, where the target service instruction is used to obtain target service data.

[0034] It should be noted that different target service instructions have different corresponding target contents. For example, the target service instruction can be an instruction to obtain memory capacity, or it can be an instruction to obtain memory usage. Although both are to obtain memory-related data, the target contents obtained are different, and the corresponding return data formats are also different. The data format corresponding to the instruction to obtain memory capacity is a numerical format, and the data format corresponding to the instruction to obtain memory usage is a percentage format. Not only are the data formats different, the parameter names of the data are also different, and the corresponding encoding after successfully obtaining the data is also different.

[0035] It is understandable that the execution subject of the present invention may be a service processing device based on a policy mode, or may be a terminal or a server, which is not specifically limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.

[0036] 102. Parse the target service instruction to determine the target calling strategy corresponding to the target service instruction.

[0037] Specifically, the server parses the return data field of the target service instruction to determine the name of the target service; the server determines the target data format corresponding to the target service based on the name of the target service; the server determines the target calling strategy that matches the target data format in a preset calling strategy table, and the target calling strategy has a corresponding target result processor, and the target result processor is used to obtain the service content corresponding to the target service, and the service content has the target data format.

[0038] For example, the target service instruction is used to collect the usage rate of physical memory. When the server obtains the target service instruction, it first parses the return data field of the target service instruction to obtain the name of the target service "physical memory usage rate", and then determines that the data format of the usage rate is a percentage value. Then, the physical memory usage estimation method strategy is selected from the pre-set calling strategy. After obtaining the usage rate of the physical content, the physical memory usage estimation method strategy converts the obtained binary result into a percentage value and returns the percentage value.

[0039] For another example, the target service instruction is used to collect the response time of the microservice. When the server obtains the target service instruction, it first parses the return data field of the target service instruction to obtain the name of the target service "microservice response time", and then determines that the data format of the response time is a decimal value in ms. Then, the corresponding time calculation method strategy is selected from the pre-set calling strategy. After obtaining the response time of the microservice, the time calculation method strategy converts the obtained binary result into a decimal value and returns the decimal value.

[0040] 103. Determine a target result processor according to a target call strategy. The target result processor is used to index a target parameter parser. The target parameter parser is used to provide target service data.

[0041] The server determines the target result processor according to the target call strategy, and the target result processor is used to index the target parameter resolver, and the target parameter resolver is used to provide target service data. Specifically, the server determines the corresponding target service parameter name according to the target call strategy; the server determines the name of the corresponding target parameter resolver based on the target service parameter name, and the target parameter resolver is used to provide target service data; the server sets the name of the target parameter resolver as the target index; the server generates the target result processor and injects the target index into the target result processor.

[0042] 104. Determine whether the target result processor has completed registration in the control inversion container.

[0043] The server determines whether the target result processor has completed registration in the control inversion container. Specifically, the server obtains the target identifier of the target result processor; the server reads the resource file of the control inversion container, and the resource file includes the registration identifier of the registered result processor; the server determines whether there is a registration identifier identical to the target identifier in the resource file; if there is a registration identifier identical to the target identifier in the resource file, the server determines that the target result processor has completed registration in the control inversion container; if there is no registration identifier identical to the target identifier in the resource file, the server determines that the target result processor has not completed registration in the control inversion container.

[0044] 105. If the target result processor completes registration in the control inversion container, determine the target interface of the target parameter resolver corresponding to the target result processor, and call the target interface to access the target parameter resolver.

[0045] If the target result processor completes registration in the inversion of control container, the server determines the target interface of the target parameter resolver corresponding to the target result processor, and calls the target interface to access the target parameter resolver.

[0046] It should be noted that a result processor corresponds to one or more parameter parsers. Among them, the implementation class of the parameter parser plays a specific strategy role, and the result processor plays an environment role. The environment role holds a reference to a strategy class for the caller to call the parameter parser. The data format in the parameter parser may be the same or different.

[0047] It is understandable that the data formats returned by multiple interfaces provided by a service are usually the same, but may be slightly different between services, so each service should have its own result processor. It is not difficult to find that the processing logic of the result processor can be reused, and it is also necessary to extract these reusable processing logics from the result processor. I call the extracted processing logic a parameter parser. There are different parameter parsers for different data formats, and different algorithms are used to obtain the data in the returned data. The data parameter name can be assigned through the construction method of the parameter parser, and the result processor only needs to hold a reference to the parameter parser. The calling logic of this embodiment is: call the method of the result processor to obtain the data in the returned data. The result processor does not directly process the request, but forwards the request to the parameter parser for processing.

[0048] In the embodiment of the present invention, when the data format of a service changes, a corresponding parameter parser is called for processing, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process, and improving the processing efficiency of the service.

[0049] See also Figure 2, another flow chart of the service processing method based on the policy pattern provided by an embodiment of the present invention, specifically includes:

[0050] 201. Receive a target service instruction sent by a terminal, where the target service instruction is used to obtain target service data.

[0051] The server receives a target service instruction sent by the terminal, where the target service instruction is used to obtain target service data.

[0052] It should be noted that different target service instructions have different corresponding target contents. For example, the target service instruction can be an instruction to obtain memory capacity, or it can be an instruction to obtain memory usage. Although both are to obtain memory-related data, the target contents obtained are different, and the corresponding return data formats are also different. The data format corresponding to the instruction to obtain memory capacity is a numerical format, and the data format corresponding to the instruction to obtain memory usage is a percentage format. Not only are the data formats different, the parameter names of the data are also different, and the corresponding encoding after successfully obtaining the data is also different.

[0053] It is understandable that the execution subject of the present invention may be a service processing device based on a policy mode, or may be a terminal or a server, which is not specifically limited here. The embodiment of the present invention is described by taking a server as the execution subject as an example.

[0054] 202. Parse the target service instruction to determine the target calling strategy corresponding to the target service instruction.

[0055] Specifically, the server parses the return data field of the target service instruction to determine the name of the target service; the server determines the target data format corresponding to the target service based on the name of the target service; the server determines the target calling strategy that matches the target data format in a preset calling strategy table, and the target calling strategy has a corresponding target result processor, and the target result processor is used to obtain the service content corresponding to the target service, and the service content has the target data format.

[0056] Among them, if the name of the target service is to count the usage rate of physical memory, the target data format corresponding to the usage rate of physical memory is determined to be a percentage value; if the name of the target service is to count the response time of microservices, the target data format corresponding to the response time of microservices is determined to be a decimal value in milliseconds.

[0057] For example, the target service instruction is used to collect the usage rate of physical memory. When the server obtains the target service instruction, it first parses the return data field of the target service instruction to obtain the name of the target service "physical memory usage rate", and then determines that the data format of the usage rate is a percentage value. Then, the physical memory usage estimation method strategy is selected from the pre-set calling strategy. After obtaining the usage rate of the physical content, the physical memory usage estimation method strategy converts the obtained binary result into a percentage value and returns the percentage value.

[0058] For another example, the target service instruction is used to collect the response time of the microservice. When the server obtains the target service instruction, it first parses the return data field of the target service instruction to obtain the name of the target service "microservice response time", and then determines that the data format of the response time is a decimal value in ms. Then, the corresponding time calculation method strategy is selected from the pre-set calling strategy. After obtaining the response time of the microservice, the time calculation method strategy converts the obtained binary result into a decimal value and returns the decimal value.

[0059] 203. Determine a target result processor according to the target call strategy. The target result processor is used to index a target parameter parser. The target parameter parser is used to provide target service data.

[0060] The server determines the target result processor according to the target call strategy, and the target result processor is used to index the target parameter resolver, and the target parameter resolver is used to provide target service data. Specifically, the server determines the corresponding target service parameter name according to the target call strategy; the server determines the name of the corresponding target parameter resolver based on the target service parameter name, and the target parameter resolver is used to provide target service data; the server sets the name of the target parameter resolver as the target index; the server generates the target result processor and injects the target index into the target result processor.

[0061] 204. Determine whether the target result processor has completed registration in the control inversion container.

[0062] The server determines whether the target result processor has completed registration in the control inversion container. Specifically, the server obtains the target identifier of the target result processor; the server reads the resource file of the control inversion container, and the resource file includes the registration identifier of the registered result processor; the server determines whether there is a registration identifier identical to the target identifier in the resource file; if there is a registration identifier identical to the target identifier in the resource file, the server determines that the target result processor has completed registration in the control inversion container; if there is no registration identifier identical to the target identifier in the resource file, the server determines that the target result processor has not completed registration in the control inversion container.

[0063] 205. If the target result processor completes registration in the inversion of control container, determine the target interface of the target parameter resolver corresponding to the target result processor, and call the target interface to access the target parameter resolver.

[0064] If the target result processor completes registration in the inversion of control container, the server determines the target interface of the target parameter resolver corresponding to the target result processor, and calls the target interface to access the target parameter resolver.

[0065] It should be noted that a result processor corresponds to one or more parameter parsers. Among them, the implementation class of the parameter parser plays a specific strategy role, and the result processor plays an environment role. The environment role holds a reference to a strategy class for the caller to call the parameter parser. The data format in the parameter parser may be the same or different.

[0066] It is understandable that the data formats returned by multiple interfaces provided by a service are usually the same, but may be slightly different between services, so each service should have its own result processor. It is not difficult to find that the processing logic of the result processor can be reused, and it is also necessary to extract these reusable processing logics from the result processor. I call the extracted processing logic a parameter parser. There are different parameter parsers for different data formats, and different algorithms are used to obtain the data in the returned data. The data parameter name can be assigned through the construction method of the parameter parser, and the result processor only needs to hold a reference to the parameter parser. The calling logic of this embodiment is: call the method of the result processor to obtain the data in the returned data. The result processor does not directly process the request, but forwards the request to the parameter parser for processing.

[0067] 206. If the target result processor has not completed registration in the control inversion container, determine the corresponding target parameter parser according to the target call strategy.

[0068] If the target result processor has not completed registration in the control inversion container, the following steps are performed: 1. The server determines the target service parameter name corresponding to the target service according to the target call strategy;

[0069] 2. The server determines the corresponding target data format according to the target service parameter name;

[0070] 3. The server generates a corresponding target parameter parser and the name of the target parameter parser based on the target data format;

[0071] For example, set the name of the target parameter parser (parameter name) for a specific data structure, set the status code to code or respCode, and the prompt content to message or msg.

[0072] 4. The server sets the name of the target parameter resolver as the target index;

[0073] 5. The server injects the target index into the target parameter parser through a preset constructor or a preset assignment function;

[0074] Among them, the construction method of the result processor is as follows:

[0075] Create the target function ResultHandler and assign a value to ResultHandler;

[0076] Alternatively, directly define the target function ResultHandler and the return type.

[0077] For example, if the target parameter parser is parameter parser A, the parsing is as follows:

[0078]

[0079]

[0080] Here A refers to the description of a type of parameter parser, which means that in order to parse data, an object is created. The object has three attributes: code, message, and data. The names of the three attribute parameters may be different. They are set through the constructor, which is a necessary operation for the initialization of the object. This is called object-oriented programming.

[0081] 6. The server determines an interface of the target parameter parser, where the interface is used to instruct the target parameter parser to obtain target service data in a target data format.

[0082] For an interface call, what is needed is the parameter value in the data. Usually, if the interface call is successful, there will be data in the data, and if the call fails, the data will be empty.

[0083] Take the following structure as an example:

[0084]

[0085] Only the content of "successfully returned data content" is obtained. The algorithm here can be understood as: first determine whether the code parameter value is 000000, if it is, return the data parameter value, if not, return the message parameter value, the message generally contains error prompts, such as incorrect input parameters, no permission to access, etc.

[0086] 207. Generate a target object corresponding to the target result processor according to the preset factory class and the target parameter parser.

[0087] The server generates the target object corresponding to the target result processor according to the preset factory class and the target parameter resolver. The factory class is actually a piece of code used by the result processor to assemble the parameter resolver and add it to the control inversion container (for example, spring ioc container). It is like a factory, so it is called a factory class.

[0088] 208. Host the target object in the control inversion container.

[0089] The server hosts the target object in the control inversion container. The control inversion container hosts multiple objects, each of which may correspond to a result processor.

[0090] 209. Allocate a corresponding configuration file for the target object, and register the target result processor in the control inversion container according to the configuration file.

[0091] The server allocates a corresponding configuration file to the target object, and registers the target result processor in the control inversion container according to the configuration file.

[0092] It should be noted that all additions or modifications are done in the preset classes, which are put together for easy management and maintenance. For example, if the X system is connected, a result processor of the X system is added to it. If the data format returned by the Y system changes, a new parameter parser is set for the result processor of the Y system.

[0093] In the embodiment of the present invention, when the data format of a service changes, a corresponding parameter parser is called for processing, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process, and improving the processing efficiency of the service.

[0094] The above describes the service processing method based on the policy mode in the embodiment of the present invention. The following describes the service processing device based on the policy mode in the embodiment of the present invention. Figure 3 , an embodiment of a service processing device based on a policy pattern in an embodiment of the present invention includes:

[0095] A receiving unit 301 is configured to receive a target service instruction sent by a terminal, wherein the target service instruction is used to obtain target service data;

[0096] The parsing unit 302 is used to parse the target service instruction and determine the target calling strategy corresponding to the target service instruction;

[0097] A first determining unit 303 is used to determine a target result processor according to the target call strategy, wherein the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide the target service data;

[0098] A judging unit 304 is used to judge whether the target result processor has completed registration in the control inversion container;

[0099] The calling unit 305 is used to determine the target interface of the target parameter parser corresponding to the target result processor if the target result processor completes registration in the control inversion container, and call the target interface to access the target parameter parser.

[0100] In the embodiment of the present invention, when the data format of a service changes, a corresponding parameter parser is called for processing, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process, and improving the processing efficiency of the service.

[0101] See also Figure 4 Another embodiment of the service processing device based on the strategy mode in the embodiment of the present invention includes:

[0102] A receiving unit 301 is configured to receive a target service instruction sent by a terminal, wherein the target service instruction is used to obtain target service data;

[0103] The parsing unit 302 is used to parse the target service instruction and determine the target calling strategy corresponding to the target service instruction;

[0104] A first determining unit 303 is used to determine a target result processor according to the target call strategy, wherein the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide the target service data;

[0105] A judging unit 304 is used to judge whether the target result processor has completed registration in the control inversion container;

[0106] The calling unit 305 is used to determine the target interface of the target parameter parser corresponding to the target result processor if the target result processor completes registration in the control inversion container, and call the target interface to access the target parameter parser.

[0107] Optionally, the parsing unit 302 specifically includes:

[0108] The parsing module 3021 is used to parse the return data field of the target service instruction and determine the name of the target service corresponding to the target service instruction;

[0109] A data format module 3022 is used to determine a target data format corresponding to the target service according to the name of the target service;

[0110] The policy determination module 3023 is used to determine a target calling policy that matches the target data format in a preset calling policy table, wherein the target calling policy has a corresponding target result processor, and the target result processor is used to obtain service content corresponding to the target service, wherein the service content has the target data format.

[0111] Optionally, the data format module 3022 is specifically used for:

[0112] Based on the target service parameter name, a corresponding initial data format is determined, where the initial data format is a binary format corresponding to the target service parameter in the target service; the binary format is converted into a target data format, where the target data format includes a decimal value format and a percentage value format.

[0113] Optionally, the first determining unit 303 is specifically configured to:

[0114] Determine the target service parameter name corresponding to the target service according to the target call strategy; determine the name of the corresponding target parameter parser based on the target service parameter name, and the target parameter parser is used to provide target service data; set the name of the target parameter parser to the target index; generate a target result processor, and inject the target index into the target result processor.

[0115] Optionally, the service processing device based on the strategy mode further includes:

[0116] A second determining unit 306 is configured to determine a corresponding target parameter parser according to the target call strategy if the target result processor has not completed registration in the control inversion container;

[0117] A generating unit 307, configured to generate a target object corresponding to the target result processor according to a preset factory class and the target parameter parser;

[0118] A hosting unit 308, configured to host the target object in the inversion of control container;

[0119] The allocation and registration unit 309 is used to allocate a corresponding configuration file to the target object and register the target result processor in the control inversion container according to the configuration file.

[0120] Optionally, the second determining unit 306 includes:

[0121] A name determination module 3061, configured to determine a target service parameter name corresponding to the target service instruction according to the target call strategy;

[0122] The format determination module 3062 is used to determine the corresponding target data format according to the target service parameter name;

[0123] A generating module 3063, configured to generate a corresponding target parameter parser and a name of the target parameter parser based on the target data format;

[0124] A setting module 3064, used to set the name of the target parameter parser to a target index;

[0125] An injection module 3065, used for injecting the target index into the target parameter parser through a preset constructor or a preset assignment function;

[0126] The interface determination module 3066 is used to determine the interface of the target parameter parser, and the interface is used to instruct the target parameter parser to obtain the target service data in the target data format.

[0127] Optionally, the determining unit 304 is specifically configured to:

[0128] Obtain a target identifier of the target result processor; read a resource file of the control inversion container, the resource file including a registration identifier of a registered result processor; determine whether there is a registration identifier identical to the target identifier in the resource file; if there is a registration identifier identical to the target identifier in the resource file, determine that the target result processor has completed registration in the control inversion container; if there is no registration identifier identical to the target identifier in the resource file, determine that the target result processor has not completed registration in the control inversion container.

[0129] In the embodiment of the present invention, a target service instruction sent by a receiving terminal is received, and the target service instruction is used to obtain target service data; the target service instruction is parsed to determine the target call strategy corresponding to the target service instruction; a target result processor is determined according to the target call strategy, and the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide target service data; it is determined whether the target result processor has completed registration in a control inversion container; if the target result processor has completed registration in a control inversion container, the target interface of the target parameter parser corresponding to the target result processor is determined, and the target interface is called to access the target parameter parser. When the data format of the service changes, the corresponding parameter parser is called for processing, which avoids the generation of a large amount of duplicate code, simplifies the data processing process, and improves the processing efficiency of the service.

[0130] above Figure 3 to Figure 4 The service processing device based on the policy mode in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The service processing device based on the policy mode in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0131] Figure 5 1 is a schematic diagram of the structure of a service processing device based on a policy pattern provided by an embodiment of the present invention. The service processing device 500 based on a policy pattern may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 501 (for example, one or more processors) and a memory 509, and one or more storage media 508 (for example, one or more mass storage devices) storing application programs 507 or data 506. Among them, the memory 509 and the storage medium 508 may be short-term storage or permanent storage. The program stored in the storage medium 508 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the service processing device based on the policy pattern. Furthermore, the processor 501 may be configured to communicate with the storage medium 508 to execute a series of instruction operations in the storage medium 508 on the service processing device 500 based on the policy pattern.

[0132] The service processing device 500 based on the policy mode may also include one or more power supplies 502, one or more wired or wireless network interfaces 503, one or more input and output interfaces 504, and / or one or more operating systems 505, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. It can be understood by those skilled in the art that Figure 5The structure of the service processing device based on the policy mode shown in the figure does not constitute a limitation on the service processing device based on the policy mode, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently. The processor 501 can perform the functions of the parsing unit 302, the first determination unit 303, the judgment unit 304, the calling unit 305, the second determination unit 306, the generation unit 307, the hosting unit 308 and the allocation registration unit 309 in the above embodiment.

[0133] Combine the following Figure 5 A detailed introduction to the various components of the service processing device based on the strategy pattern:

[0134] Processor 501 is the control center of the service processing device based on the policy mode, and can process according to the set service processing method based on the policy mode. Processor 501 uses various interfaces and lines to connect the various parts of the entire service processing device based on the policy mode, and executes various functions and processes data of the service processing device based on the policy mode by running or executing software programs and / or modules stored in memory 509, and calling data stored in memory 509, thereby avoiding the generation of a large amount of duplicate code, simplifying the data processing process, and improving the processing efficiency of the service. Storage medium 508 and memory 509 are both carriers for storing data. In the embodiment of the present invention, storage medium 508 can refer to an internal memory with a small storage capacity but a fast speed, and memory 509 can be an external memory with a large storage capacity but a slow storage speed.

[0135] The memory 509 can be used to store software programs and modules. The processor 501 executes various functional applications and data processing of the service processing device 500 based on the policy mode by running the software programs and modules stored in the memory 509. The memory 509 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as parsing the target service instruction and determining the target call strategy corresponding to the target service instruction), etc.; the data storage area can store data created according to the use of the service processing device based on the policy mode (such as a target result processor, etc.). In addition, the memory 509 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices. The service processing method program based on the policy mode provided in the embodiment of the present invention and the received data stream are stored in the memory, and when needed, the processor 501 calls from the memory 509.

[0136] When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, twisted pair) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or a data center that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., an optical disk), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.

[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0138] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0139] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] In addition, each functional unit in the embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0141] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0142] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A service processing method based on a strategy pattern, characterized in that: include: receiving a target service instruction sent by a terminal, wherein the target service instruction is used to obtain target service data; Parsing the target service instruction to determine a target calling strategy corresponding to the target service instruction; Determine a target result processor according to the target call strategy, the target result processor is used to index a target parameter parser, and the target parameter parser is used to provide the target service data; Determine whether the target result processor has completed registration in the control inversion container; If the target result processor completes registration in the control inversion container, determining the target interface of the target parameter parser corresponding to the target result processor, and calling the target interface to access the target parameter parser; The parsing of the target service instruction to determine the target call strategy corresponding to the target service instruction includes: parsing the return data field of the target service instruction to determine the name of the target service corresponding to the target service instruction; Determine the target data format corresponding to the target service according to the name of the target service; determine the target calling strategy that matches the target data format in a preset calling strategy table, the target calling strategy has a corresponding target result processor, and the target result processor is used to obtain the service content corresponding to the target service, and the service content has the target data format.

2. The service processing method based on the policy pattern according to claim 1 is characterized in that: The determining the target data format corresponding to the target service according to the name of the target service includes: If the name of the target service is to count the usage of physical memory, then determine that the target data format corresponding to the usage of physical memory is a percentage value; If the name of the target service is to count the response time of a microservice, it is determined that the target data format corresponding to the response time of the microservice is a decimal value.

3. The service processing method based on the policy pattern according to claim 1 is characterized in that: The determining of a target result processor according to the target call strategy, the target result processor being used to index a target parameter parser, the target parameter parser being used to provide the target service data, comprises: Determine the target service parameter name corresponding to the target service according to the target call strategy; Determine the name of the corresponding target parameter parser based on the target service parameter name, the target parameter parser is used to provide target service data; Setting the name of the target parameter parser to the target index; A target result processor is generated, and the target index is injected into the target result processor.

4. The service processing method based on the policy pattern according to claim 1 is characterized in that: After determining whether the target result processor has completed registration in the control inversion container, the method further includes: If the target result processor has not completed registration in the control inversion container, determining the corresponding target parameter parser according to the target call strategy; Generate a target object corresponding to the target result processor according to a preset factory class and the target parameter parser; Hosting the target object in the control inversion container; A corresponding configuration file is allocated to the target object, and the target result processor is registered in the control inversion container according to the configuration file.

5. The service processing method based on the policy pattern according to claim 4 is characterized in that: Determining the corresponding target parameter parser according to the target call strategy includes: Determine a target service parameter name corresponding to the target service instruction according to the target call strategy; Determine the corresponding target data format according to the target service parameter name; Generate a corresponding target parameter parser and a name of the target parameter parser based on the target data format; Setting the name of the target parameter parser to the target index; Injecting the target index into the target parameter parser through a preset constructor or a preset assignment function; An interface of the target parameter parser is determined, where the interface is used to instruct the target parameter parser to obtain target service data in a target data format.

6. The service processing method based on the strategy pattern according to any one of claims 1 to 5, characterized in that: The step of determining whether the target result processor has completed registration in the control inversion container includes: Obtaining a target identifier of the target result processor; Reading a resource file of the control inversion container, wherein the resource file includes a registration identifier of a registered result processor; Determine whether there is a registration identifier identical to the target identifier in the resource file; If there is a registration identifier identical to the target identifier in the resource file, determining that the target result processor completes registration in the control inversion container; If the registration identifier identical to the target identifier does not exist in the resource file, it is determined that the target result processor has not completed registration in the inversion of control container.

7. A service processing device based on a policy mode, characterized in that: include: A receiving unit, configured to receive a target service instruction sent by a terminal, wherein the target service instruction is used to obtain target service data; A parsing unit, used to parse the target service instruction and determine a target calling strategy corresponding to the target service instruction; A first determining unit, configured to determine a target result processor according to the target call strategy, wherein the target result processor is configured to index a target parameter parser, and the target parameter parser is configured to provide the target service data; A judging unit, used to judge whether the target result processor has completed registration in the control inversion container; A calling unit, for determining a target interface of a target parameter parser corresponding to the target result processor, and calling the target interface to access the target parameter parser, if the target result processor completes registration in the control inversion container; The parsing of the target service instruction to determine the target call strategy corresponding to the target service instruction includes: parsing the return data field of the target service instruction to determine the name of the target service corresponding to the target service instruction; Determine the target data format corresponding to the target service according to the name of the target service; determine the target calling strategy that matches the target data format in a preset calling strategy table, the target calling strategy has a corresponding target result processor, and the target result processor is used to obtain the service content corresponding to the target service, and the service content has the target data format.

8. A service processing device based on a policy mode, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the service processing method based on the policy pattern as described in any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the service processing method based on the policy pattern as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Interface call data processing method and apparatus, and computer device

    CN108255905A

  • Apparatuses, methods and systems for an API call abstractor

    US20110202905A1