A REST result set dynamic processing method and system based on microservice architecture
By selectively intervening in the control processing layer of the microservice architecture, configuring the attribute processor and adapter, dynamically processing the result set Body data, the complexity of data association query under the microservice architecture is solved, and the code simplicity and efficient query are achieved.
Patent Information
- Application Number
- CN202210891853.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-27
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2042-07-27
AI Technical Summary
Under the microservice architecture, data association query operations are too complex and code coupling is high, resulting in increased code redundancy and complexity, and maintenance is difficult.
By selectively intervening at the control processing layer, the attribute processor and attribute processing adapter are configured to perform attribute matching and dynamic processing on the serialized result set Body data, and data addition, replacement and conversion are realized.
It reduces the complexity of code implementation, reduces redundant code, improves development efficiency and query speed, and solves the complexity problem of data-related query.
Smart Images

Figure CN115268870B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to a REST result set dynamic processing method and system based on a microservice architecture. Background Art
[0002] Table association query is very familiar to any program developer. In the past, for monolithic applications, developers basically completed most query business scenarios through SQL association query for data association query; however, the limitations and scalability of monolithic applications have become difficult to support larger business volumes as the business volume increases. In recent years, with the rise of microservice technology applications, enterprises have split and separated some functional modules in order to reduce service coupling, and the intensity of splitting has become more and more detailed with staffing. The splitting of business will involve database splitting, which brings some problems, such as the problem of upstream and downstream business association query of some key fields. If you want to achieve data association, you need to do special processing in the program, such as: fetching the data of the associated service and then merging and processing the output to meet the needs of the page or interface. This processing method brings a series of problems, such as each business that needs to be merged must implement the data retrieval and merge code business logic process, which greatly increases the code redundancy and code complexity, and at the same time increases the difficulty of code implementation, which is not convenient for reading and maintenance. Summary of the invention
[0003] The purpose of the present invention is to provide a REST result set dynamic processing method and system based on microservice architecture, which achieves the purpose of special data processing by selectively intervening in the control processing layer and performing special object processing after serializing the Body, and solves the table association query problem with more concise and convenient code to meet business needs.
[0004] To achieve the above object, the present invention proposes the following technical solution: a REST result set dynamic processing method based on microservice architecture, comprising:
[0005] Add a first annotation on the REST-API interface for enabling the post-processing function of the custom attribute of the REST result set, wherein the first annotation includes a first attribute tag consisting of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the tag; or add a second annotation on the REST-API interface for enabling the post-processing function of the custom attribute of the REST result set, and add a pre-processing attribute action annotation on the return class attribute, wherein the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute;
[0006] Call the REST-API interface to obtain the result set body data after object serialization;
[0007] Determine and confirm the result set body data that needs to be post-processed and record it as the data to be processed;
[0008] A result set component configured with an attribute processor and an attribute processing adapter is introduced to recursively match the data to be processed according to the first attribute label or the pre-processing attribute action annotation;
[0009] Determine and obtain the basic attribute matching the first attribute tag or the pre-processing attribute action annotation in the data to be processed, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adaptation processor determines the attribute processing action corresponding thereto; wherein the attribute processing action includes adding attributes, replacing attributes, and converting attribute values;
[0010] The attribute processor dynamically processes the basic attributes according to the determined attribute processing action.
[0011] Furthermore, it also includes:
[0012] Add a third annotation on the REST-API interface to enable the post-processing function of the custom attribute of the REST result set, wherein the third annotation includes a second attribute label consisting of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the label;
[0013] The result set component recursively matches the data to be processed according to the second attribute tag, and when a basic attribute matching the second attribute tag exists in the data to be processed, the attribute processor deletes the basic attribute.
[0014] Furthermore, the process of the attribute processor dynamically processing the basic attribute according to the supplementary attribute is as follows:
[0015] Determine the target attributes;
[0016] The attribute processor performs an RPC query based on the attribute value of the extracted basic attribute to obtain the attribute query result;
[0017] Store the attribute query result in the attribute cache, and add the attribute name and attribute value of the target attribute to the attribute query result.
[0018] Furthermore, the process of the attribute processor dynamically processing the basic attribute according to the replacement attribute is as follows:
[0019] Determine the target attributes;
[0020] The attribute processor performs an RPC query based on the attribute value of the extracted basic attribute to obtain the attribute query result;
[0021] Store the attribute query result to the attribute cache, delete the basic attributes in the attribute query result and add the associated target attributes to the attribute query result.
[0022] Furthermore, the process of the attribute processor dynamically processing the basic attribute according to the conversion attribute value is as follows:
[0023] Determine the target attribute value;
[0024] The attribute processor converts the attribute value of the extracted basic attribute into the target attribute value according to the conversion rules preset by the attribute processing adapter.
[0025] Furthermore, when the attribute condition in the data to be processed is equal to the attribute condition of the basic attribute previously dynamically processed by the attribute processor, the attribute adaptation processor directly calls the cache data of the attribute cache library to complete the addition or replacement of the target attribute.
[0026] Another technical solution of the present invention is to disclose a REST result set dynamic processing system based on a microservice architecture, the system comprising:
[0027] A first adding module is used to add a first annotation on the REST-API interface for enabling a post-processing function of a custom attribute of a REST result set, wherein the first annotation includes a first attribute tag consisting of attribute names of a plurality of basic attributes, and assigns an attribute processing action corresponding to any attribute in the tag; or to add a second annotation on the REST-API interface for enabling a post-processing function of a custom attribute of a REST result set, and to add a pre-processing attribute action annotation on a return class attribute, wherein the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute;
[0028] The acquisition module is used to call the REST-API interface to obtain the body data of the result set after object serialization;
[0029] The first judgment module is used to judge and determine the result set body data that needs to be post-processed, recorded as data to be processed;
[0030] A recursive matching module, used for introducing a result set component configured with an attribute processor and an attribute processing adapter to recursively match the data to be processed according to the first attribute label or the pre-processing attribute action annotation;
[0031] The second judgment module is used to judge and obtain the basic attribute matching the first attribute tag or the pre-processing attribute action annotation in the data to be processed, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adaptation processor determines the attribute processing action corresponding thereto; wherein the attribute processing action includes adding attributes, replacing attributes, and converting attribute values;
[0032] The first attribute processing module is used for the attribute processor to dynamically process the basic attributes according to the determined attribute processing action.
[0033] Furthermore, the system also includes: a second adding module, used to add a third annotation on the REST-API interface for enabling the REST result set custom attribute post-processing function, the third annotation includes a second attribute label composed of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the label; a second attribute processing module, used for the result set component to recursively match the data to be processed according to the second attribute label, and when there is a basic attribute matching the second attribute label in the data to be processed, the attribute processor deletes the basic attribute.
[0034] Furthermore, the execution unit of the attribute processor in the first attribute processing module for dynamically processing the attribute according to the supplementary attribute or the replacement attribute includes:
[0035] A first determining unit, used to determine a target attribute or a target attribute value;
[0036] A query unit, used for the attribute processor to perform an RPC query according to the attribute value of the basic attribute extracted by it, and obtain the attribute query result;
[0037] The storage execution unit is used to store the attribute query result in the attribute cache, add the attribute name and attribute value of the target attribute to the attribute query result, or delete the basic attribute in the attribute query result and add the associated target attribute to the attribute query result.
[0038] The present invention also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, the above-mentioned REST result set dynamic processing method based on the microservice architecture is implemented.
[0039] It can be seen from the above technical solutions that the technical solutions of the present invention have the following beneficial effects:
[0040] The method and system for dynamically processing REST result sets based on microservice architecture disclosed in the present invention aims to solve the problems of overly complex data association query operations and high code coupling under microservice architecture; the solution selectively intervenes in the control processing layer, based on RestController, and performs special object processing after serializing the Body; and then completes attribute processing by matching attributes through the set attribute processor and attribute processing adapter, meeting the requirements of multiple result attribute processing scenarios. When the solution is applied to data association query under microservice architecture, it has the following advantages:
[0041] 1. Solve the problem of hot field association query under cross-service and cross-database programs, without the need to repeatedly write supplementary field logic; reduce the association query of tables within the program. The fewer table associations, the faster the relative query, which improves the query speed; reduce the complexity of code implementation, improve development efficiency, and reduce redundant code;
[0042] 2. When applied to sensitive data queries, solve the problem that some fields in the REST result set need to be desensitized, escaped, and transcoded;
[0043] 3. When applied to automatic query of persistence layer framework data, solve the problem of sensitive fields in REST result sets not being deleted, exposing sensitive data and data structure;
[0044] 4. Solve the problem that the redundant storage of business-related data is inaccurate, which leads to maintenance difficulties, and the SQL-related coupling query cannot be made after non-redundant storage is deleted.
[0045] It should be appreciated that all combinations of the foregoing concepts, as well as additional concepts described in greater detail below, may be considered to be part of the inventive subject matter of the present disclosure, provided such concepts are not mutually inconsistent.
[0046] The foregoing and other aspects, embodiments and features of the present invention can be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as the features and / or beneficial effects of the exemplary embodiments, will be apparent from the following description or learned from the practice of the specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings are not drawn to scale according to actual reference objects. In the accompanying drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For the sake of clarity, not every component is labeled in each figure. Now, embodiments of various aspects of the present invention will be described by way of example and with reference to the accompanying drawings, in which:
[0048] Figure 1 This is a flow chart of a method for dynamically processing a REST result set based on a microservice architecture of the present invention;
[0049] Figure 2 The figure is a schematic diagram of the dynamic processing process of the REST result set based on the microservice architecture according to an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be the common meaning understood by people with general skills in the field to which the present invention belongs.
[0051] The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular forms of "a", "an" or "the" and other similar words do not indicate a quantitative limitation, but indicate the existence of at least one. Words such as "include" or "comprise" mean that the elements or objects appearing before "include" or "comprise" cover the features, wholes, steps, operations, elements and / or components listed after "include" or "comprise", and do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0052] Based on the rise of microservice technology applications in the prior art, enterprises have reduced the coupling of services by finely splitting their businesses, which has led to the need to perform special processing on programs when querying the upstream and downstream businesses of key fields, such as taking the data of related services and then merging and processing the output. This processing method requires the implementation of the business logic of data retrieval and merging codes for each related query, resulting in a significant increase in code redundancy and complexity, and the code is difficult to implement and maintain. The present invention proposes a REST result set dynamic processing method and system based on a microservice architecture, which selectively intervenes in the control processing layer, configures an attribute processor and an attribute processing adapter, and performs attribute processing on the data after serialization of the Body data according to different attribute processing actions to meet the needs of each target attribute processing scenario; when querying related queries, not only is there no need to repeatedly write the supplementary field logic and reduce redundant code, but also reduces the complexity of code implementation, improves development efficiency, and increases query speed.
[0053] The initial invention concept of the present invention is based on "how to solve data association query", such as: business subject "person", and when developers design business tables, they basically use UserId to set association fields. For the program, it is to perceive the meaning or business relationship represented by UserId, but for business users, it is obviously not enough to just display UserId. At this time, it is necessary to add UserName while displaying UserId. However, when the program is relatively independent and does not belong to the same database, remote calling will be considered, that is, remote query of the "unified user center" user name, and then add UserName in the program; the supplement process is organized as follows: first create a VO object with UserName, then remotely call the user object or collection, and finally complete the object attribute addition. For a simple processing object, this process is fast and convenient, but for a list object, it is necessary to double-loop the queried business object and add the business subject UserName attribute after judgment. This process may still have some data matching situations that are not rigorous, such as the user has been deleted, but the user ID is still used in the business data. The above problems can be solved through rigorous code judgment, but if the objects are nested more than two levels, the code implementation provided by the program developer will be very complicated, so the probability of error is very high and subsequent maintenance is relatively difficult.
[0054] It is known that the current JSON format data interface is favored by developers because its attribute fields are easy to maintain and flexible; therefore, the present invention discloses a new solution, based on the Rest result set returned under the SpringBoot framework as a starting point, when the control processing layer serializes the object into JSON format data, the idea of adding the required fields is added, such as adding attributes. Taking UserName as an example, only adding the UserName attribute is not enough to solve the above problem. It is necessary to further clarify the attribute Value of UserName, that is, to obtain the UserName value according to the UserId value; for the Key-Value model, such as: UserId is 1, the corresponding user name in the data table is admin, and the attribute Value can be obtained.
[0055] The following is a further detailed introduction to the REST result set dynamic processing method and system based on microservice architecture disclosed in the present invention in conjunction with the embodiments shown in the accompanying drawings.
[0056] Combination Figure 1 and Figure 2 As shown, the REST result set dynamic processing method based on the microservice architecture disclosed in the present invention includes the following steps:
[0057] Step S102, adding a first annotation for enabling the post-processing function of the custom attribute of the REST result set on the REST-API interface, wherein the first annotation includes a first attribute label consisting of the attribute names of several basic attributes, and assigning an attribute processing action corresponding to any attribute in the label; or adding a second annotation for enabling the post-processing function of the custom attribute of the REST result set on the REST-API interface, and adding a pre-processing attribute action annotation on the return class attribute, wherein the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute;
[0058] This step aims to propose two methods to enter the post-processing flow. During the specific implementation, developers can arrange to enable components to enter the post-processing function of the REST result set custom attributes according to the actual needs of the current scenario.
[0059] Step S104, calling the REST-API interface to obtain the result set body data after object serialization;
[0060] First, after receiving an external request through the REST-API interface, the control processing layer will call the business logic layer for business processing. The business logic layer will initiate access to the data access layer to the database according to business needs and respond to the control processing layer.
[0061] Step S106, judge and determine the result set body data that needs to be post-processed, and record it as the data to be processed; the process of this step mainly reads the first attribute label or pre-processing attribute action annotation preset by the interface in step S102 in the form of annotation. When there is a basic attribute matching the first attribute label or corresponding to the pre-processing attribute action annotation in the serialized result set body data, it is determined to be data that needs to be post-processed, that is, the REST result set custom attribute post-processing function is started. In specific implementation, the return data directly enters the post-processing function after matching the annotation configured with the interface, and the data to be processed is not obtained; in some cases, all return data needs to be post-processed. In this type of process, the return data, such as the result set body data, directly enters the iterative matching process of step S108.
[0062] Step S108, introducing a result set component configured with an attribute processor and an attribute processing adapter to recursively match the data to be processed according to the first attribute tag or the pre-processing attribute action annotation;
[0063] The result set component can be referenced by any service and perform dynamic attribute processing. The attribute processor mainly completes the attribute processing action, the attribute processing adapter mainly completes the attribute matching, and provides the processing method. The attribute processing adapter cooperates with the attribute processor to complete the attribute processing. The basic attribute in the scheme is the attribute in the original Body data, which is the premise attribute and the source attribute based on which the processing purpose is completed.
[0064] Step S110, determining and obtaining the basic attribute matching the first attribute tag or the pre-processing attribute action annotation in the data to be processed, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adaptation processor determines the attribute processing action corresponding thereto; wherein the attribute processing action includes adding an attribute, replacing an attribute, and converting an attribute value;
[0065] Step S112: the attribute processor dynamically processes the basic attributes according to the determined attribute processing action.
[0066] As an optional embodiment, the REST result set dynamic processing method based on the microservice architecture of the present invention also includes: adding a third annotation on the REST-API interface to enable the custom attribute post-processing function of the REST result set, the third annotation includes a second attribute label composed of the attribute names of several basic attributes, and assigning an attribute processing action corresponding to any attribute in the label; the attribute processor recursively matches the data to be processed according to the second attribute label, and when there is a basic attribute matching the second attribute label in the data to be processed, the attribute processor deletes the basic attribute. The above method process implements the attribute processing action of deleting the attribute, that is, deleting a certain basic attribute to achieve the purpose of clearing the attribute and value in the result, for example, deleting sensitive fields such as passwords and keys.
[0067] As an optional embodiment, the attribute processing actions of the preprocessing attribute action annotation include deleting attributes in addition to adding attributes, replacing attributes, and converting attribute values; when the result set component recursively matches an attribute to the data to be processed according to the preprocessing attribute action annotation, and the attribute processing action corresponding to the attribute is a delete attribute action, the attribute processor of the result set component directly deletes the attribute in the data to be processed.
[0068] In specific implementation, the first attribute tag and the second attribute tag are synchronously configured to the REST-API interface by the first annotation. The only difference is that the result set component has different processing actions for each recursively matched attribute. For some attributes, the attribute processing action is determined by the attribute adapter processor and then executed by the attribute processor, and for some attributes, the action is directly executed by the attribute processor.
[0069] When step S112 of this embodiment is specifically implemented, the process in which the attribute processor dynamically processes the basic attributes in sequence according to the supplementary attributes, the replacement attributes and the conversion attribute values is as follows:
[0070] For supplementary attributes, the target attribute is supplemented based on a certain attribute to achieve the purpose of attribute association. The processing process includes: determining the target attribute, which is the attribute supplemented to achieve the processing purpose; the attribute processor performs RPC query based on the attribute value of the basic attribute it extracts to obtain the attribute query result; the attribute query result is stored in the attribute cache, and the attribute name and attribute value of the target attribute are supplemented to the attribute query result. Supplementary attributes means adding the name and value of the target attribute to the original query result, for example, adding the department name based on the department ID and the device name based on the device ID.
[0071] For replacing attributes, the target attribute is replaced based on a certain attribute to achieve the purpose of attribute replacement. The processing process includes: determining the target attribute; the attribute processor performs RPC query based on the attribute value of the basic attribute it extracts to obtain the attribute query result; storing the attribute query result in the attribute cache, deleting the basic attribute in the attribute query result and adding the associated target attribute to the attribute query result. Replacing an attribute means deleting the original basic attribute field in the original query result, and then putting the target attribute field and value into the query result, for example, replacing the tenant ID.
[0072] For converting attribute values, the conversion of the value of the target attribute is completed based on a certain attribute bit to achieve the purpose of attribute value conversion. The processing process includes: determining the target attribute value; the attribute processor converts the attribute value of the extracted basic attribute into the target attribute value according to the conversion rules preset by the attribute processing adapter. For example, the middle 4 digits of the mobile phone number are marked with stars, a ciphertext is decrypted, the gender (M, F) is converted into Chinese (male, female), (1, 0) is converted into (on, off), etc. In some special cases, such as when a dictionary query is required or the target attribute value has multiple enumeration values, the execution process of the attribute value conversion action can also use RPC query to obtain a solution for caching the query structure into the attribute cache library after conversion.
[0073] In order to enhance the capability of the attribute adaptation processor, the corresponding queries are usually cached. When the REST-API interface is called for the first database request, the later iterator will cache the corresponding data to improve the processing speed of the adaptation processor. Then, when the attribute conditions in the data to be processed are equivalent to the attribute conditions of the basic attributes that the attribute processor has dynamically processed first, the attribute adaptation processor directly calls the cached data of the attribute cache library to complete the addition or replacement of the target attribute.
[0074] The above-mentioned disclosed REST result set dynamic processing method based on microservice architecture handles the result attribute processing scenarios of addition, replacement, conversion and deletion, which can solve some common problems in the REST result set processing process in a targeted manner, and can achieve the purpose of one-time expansion and multiple uses through practice, and also achieve the purpose of decoupling and low code.
[0075] In an embodiment of the present invention, an electronic device is also provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, the dynamic processing method of a REST result set based on a microservice architecture in the above embodiment is implemented.
[0076] The above program can be run in a processor, or it can be stored in a memory, that is, a computer-readable medium, which includes permanent and non-permanent, removable and non-removable media. Information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media, such as modulated data signals and carrier waves.
[0077] These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in a block or multiple blocks may be implemented by different modules corresponding to different method steps.
[0078] In this embodiment, such a device or system is provided, which can be called a REST result set dynamic processing system based on a microservice architecture, and the system includes: a first adding module, which is used to add a first annotation on the REST-API interface to enable the post-processing function of the custom attribute of the REST result set, the first annotation includes a first attribute label composed of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the label; or is used to add a second annotation on the REST-API interface to enable the post-processing function of the custom attribute of the REST result set, and add a pre-processing attribute action annotation on the return class attribute, the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute; an acquisition module is used to call the REST-API interface to obtain the object sequence The columnized result set body data; a first judgment module, used to judge and determine the result set body data that needs to be post-processed, recorded as the data to be processed; a recursive matching module, used to introduce a result set component configured with an attribute processor and an attribute processing adapter to recursively match the data to be processed according to the first attribute label or the pre-processing attribute action annotation; a second judgment module, used to judge and obtain the basic attributes in the data to be processed that match the first attribute label or the pre-processing attribute action annotation, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adapter processor determines the corresponding attribute processing action; wherein the attribute processing action includes adding attributes, replacing attributes, and converting attribute values; the first attribute processing module, used for the attribute processor to dynamically process the basic attributes according to the determined attribute processing action.
[0079] The system is used to implement the steps of the REST result set dynamic processing method based on the microservice architecture disclosed in the above embodiment, which have been described and will not be repeated here.
[0080] For example, the system also includes a second adding module, which is used to add a third annotation on the REST-API interface to enable the REST result set custom attribute post-processing function, wherein the third annotation includes a second attribute label composed of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the label; a second attribute processing module, which is used for the result set component to recursively match the data to be processed according to the second attribute label, and when there is a basic attribute matching the second attribute label in the data to be processed, the attribute processor deletes the basic attribute.
[0081] For another example, the execution unit for the attribute processor in the first attribute processing module to dynamically process according to the supplementary attribute or replacement attribute includes: a first determination unit, used to determine the target attribute or target attribute value; a query unit, used for the attribute processor to perform an RPC query according to the attribute value of the basic attribute extracted by it to obtain the attribute query result; a storage execution unit, used to store the attribute query result in the attribute cache, supplement the attribute name and attribute value of the target attribute to the attribute query result or delete the basic attribute in the attribute query result and supplement the associated target attribute to the attribute query result. The first attribute processing module implements the processing process of supplementing attributes or replacing attributes in the attribute processing action.
[0082] The method and system disclosed in the present invention fully solve the problems of overly complex data association query operations, large code coupling and high redundancy under the microservice architecture, and realize the purpose of special data processing by selectively intervening in the control processing layer. The scheme is based on RestController as a premise, and after serializing the Body data, attribute matching is performed according to the configured attribute processor and attribute processing adapter to complete attribute processing; the present invention can also be used to solve the problem that some fields of the REST result set need to be desensitized, escaped and transcoded, and solve the problem that sensitive fields of the REST result set are not deleted, and sensitive data and data structure are exposed.
[0083] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
Claims
1. A REST result set dynamic processing method based on microservice architecture, characterized in that: include: Add a first annotation on the REST-API interface for enabling the post-processing function of the custom attribute of the REST result set, wherein the first annotation includes a first attribute tag consisting of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the tag; or add a second annotation on the REST-API interface for enabling the post-processing function of the custom attribute of the REST result set, and add a pre-processing attribute action annotation on the return class attribute, wherein the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute; Call the REST-API interface to obtain the result set body data after object serialization; Determine and confirm the result set body data that needs to be post-processed and record it as the data to be processed; A result set component configured with an attribute processor and an attribute processing adapter is introduced to recursively match the data to be processed according to the first attribute label or the pre-processing attribute action annotation; Determine and obtain the basic attribute matching the first attribute tag or the pre-processing attribute action annotation in the data to be processed, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adaptation processor determines the attribute processing action corresponding thereto; wherein the attribute processing action includes adding attributes, replacing attributes, and converting attribute values; The attribute processor dynamically processes the basic attributes according to the determined attribute processing action.
2. According to the method for dynamic processing of REST result set based on microservice architecture according to claim 1, it is characterized in that: Also includes: Add a third annotation on the REST-API interface to enable the post-processing function of the custom attribute of the REST result set, wherein the third annotation includes a second attribute label consisting of the attribute names of several basic attributes, and assigns an attribute processing action corresponding to any attribute in the label; The result set component recursively matches the data to be processed according to the second attribute tag, and when a basic attribute matching the second attribute tag exists in the data to be processed, the attribute processor deletes the basic attribute.
3. The method for dynamically processing REST result sets based on microservice architecture according to claim 1 is characterized in that: The process of the attribute processor dynamically processing the basic attribute according to the supplementary attribute is as follows: Determine the target attributes; The attribute processor performs an RPC query based on the attribute value of the extracted basic attribute to obtain the attribute query result; Store the attribute query result in the attribute cache, and add the attribute name and attribute value of the target attribute to the attribute query result.
4. According to the microservice architecture-based REST result set dynamic processing method according to claim 1, it is characterized in that: The process of the attribute processor dynamically processing the basic attribute according to the replacement attribute is as follows: Determine the target attributes; The attribute processor performs an RPC query based on the attribute value of the extracted basic attribute to obtain the attribute query result; Store the attribute query result to the attribute cache, delete the basic attributes in the attribute query result and add the associated target attributes to the attribute query result.
5. The method for dynamically processing REST result sets based on microservice architecture according to claim 1 is characterized in that: The process of the attribute processor dynamically processing the basic attribute according to the conversion attribute value is as follows: Determine the target attribute value; The attribute processor converts the attribute value of the extracted basic attribute into the target attribute value according to the conversion rules preset by the attribute processing adapter.
6. The method for dynamically processing a REST result set based on a microservice architecture according to any one of claims 3 or 4, characterized in that: When the attribute conditions in the data to be processed are equal to the attribute conditions of the basic attributes that the attribute processor has previously dynamically processed, the attribute adaptation processor directly calls the cached data of the attribute cache library to complete the addition or replacement of the target attribute.
7. A REST result set dynamic processing system based on microservice architecture, characterized in that: include: A first adding module is used to add a first annotation on the REST-API interface for enabling a post-processing function of a custom attribute of a REST result set, wherein the first annotation includes a first attribute tag consisting of attribute names of a plurality of basic attributes, and assigns an attribute processing action corresponding to any attribute in the tag; or to add a second annotation on the REST-API interface for enabling a post-processing function of a custom attribute of a REST result set, and to add a pre-processing attribute action annotation on a return class attribute, wherein the pre-processing attribute action annotation includes an attribute processing action corresponding to any attribute in the return class attribute; The acquisition module is used to call the REST-API interface to obtain the body data of the result set after object serialization; The first judgment module is used to judge and determine the result set body data that needs to be post-processed, recorded as the data to be processed; A recursive matching module, used for introducing a result set component configured with an attribute processor and an attribute processing adapter to recursively match the data to be processed according to the first attribute label or the pre-processing attribute action annotation; The second judgment module is used to judge and obtain the basic attribute matching the first attribute tag or the pre-processing attribute action annotation in the data to be processed, so that the attribute processor of the result set component extracts the attribute name and attribute value of the matching basic attribute, and the attribute adaptation processor determines the attribute processing action corresponding thereto; wherein the attribute processing action includes adding attributes, replacing attributes, and converting attribute values; The first attribute processing module is used for the attribute processor to dynamically process the basic attributes according to the determined attribute processing action.
8. The REST result set dynamic processing system based on microservice architecture according to claim 7 is characterized in that: Also includes: A second adding module is used to add a third annotation on the REST-API interface for enabling a custom attribute post-processing function of a REST result set, wherein the third annotation includes a second attribute label consisting of attribute names of a plurality of basic attributes, and assigns an attribute processing action corresponding to any attribute in the label; The second attribute processing module is used for the result set component to recursively match the data to be processed according to the second attribute tag, and when there is a basic attribute matching the second attribute tag in the data to be processed, the attribute processor deletes the basic attribute.
9. The REST result set dynamic processing system based on microservice architecture according to claim 7 is characterized in that: The execution unit for dynamically processing the attribute processor in the first attribute processing module according to the supplementary attribute or the replacement attribute includes: A first determining unit, used to determine a target attribute or a target attribute value; A query unit, used for the attribute processor to perform an RPC query according to the attribute value of the basic attribute extracted by it, and obtain the attribute query result; The storage execution unit is used to store the attribute query result in the attribute cache, add the attribute name and attribute value of the target attribute to the attribute query result, or delete the basic attribute in the attribute query result and add the associated target attribute to the attribute query result.
10. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, the method for dynamically processing a REST result set based on a microservice architecture as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method for generating REST service and achieving REST and corresponding equipment
CN103399734A
REST-based multi-engine big data task management method
CN112130976A