Aggregate query method, device, medium and electronic device
By configuring aggregation query in the application gateway, the problem of cross-service and cross-aggregation query assembly is solved, the implementation and maintenance difficulty is reduced, and the isolation between aggregations and high cohesion and low coupling characteristics are maintained.
Patent Information
- Application Number
- CN202411878309.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-04-04
AI Technical Summary
In the DDD-based microservice architecture design, cross-service and cross-aggregation query assembly is difficult to achieve, and the traditional method increases the workload and maintenance difficulty of the front-end or back-end, destroying the isolation between aggregations.
By performing configurations of the first aggregation and the second aggregation in the application gateway, the query results of the first aggregation are obtained, the target parameters are extracted, the configuration information of the second aggregation is obtained, the target parameters are called to merge the second query results into the first query results, and the target query results are formed.
It reduces the difficulty of implementation and maintenance of cross-aggregation queries, avoids the problem of traditional methods requiring front-end or back-end development intervention, and ensures the original aggregation isolation of the back-end and the high cohesion and low coupling characteristics between aggregations.
Smart Images

Figure CN119759938A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the field of database technology, and in particular relates to an aggregate query method, an aggregate query device, a computer-readable storage medium, and an electronic device. Background Art
[0002] In the microservice architecture design based on DDD (Domain-Driven Design), in order to ensure the high cohesion and low coupling characteristics of the domain, the domain is broken down into different bounded contexts (i.e. microservices) and aggregations. However, when querying, sometimes it is necessary to face cross-service and cross-aggregate query assembly.
[0003] When front-end aggregation assembly query is adopted, although the isolation of back-end aggregation is guaranteed, the workload and maintenance difficulty of the front-end are increased. When back-end aggregation assembly-cross-aggregation query is adopted, although the isolation of back-end aggregation is guaranteed, the workload and maintenance difficulty of back-end aggregation conversion are increased. When back-end aggregation assembly-lightweight CQRS (Command Query Responsibility Segregation) query is adopted, although the implementation difficulty of cross-aggregation query is reduced to a certain extent, it is only applicable to cross-aggregation assembly query within the same microservice, because the main aggregation is too involved in the slave aggregation, the coupling is high, and the isolation between aggregations is destroyed. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present disclosure provides an aggregate query method, an aggregate query device, a computer-readable storage medium and an electronic device.
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided an aggregate query method, which is applied to an application gateway, and the method includes: Obtaining first configuration information of the first aggregation, and intercepting a first query result of the first aggregation according to the first configuration information; Extracting target parameters from the first query result according to the first configuration information, and acquiring second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation; The second configuration information is called according to the target parameter to obtain a second query result, and the second query result is merged into the first query result to obtain a target query result.
[0006] Optionally, the target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: updating the second configuration information according to the context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a first response result; The first response result is parsed, and a second query result is extracted from the parsed first response result according to the second configuration information.
[0007] Optionally, the target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: determining a first query type according to the second configuration information, and converting the context parameter according to the first query type to obtain a converted context parameter; updating the second configuration information according to the converted context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a second response result; The second response result is parsed, and a second query result is extracted from the parsed second response result according to the second configuration information.
[0008] Optionally, converting the context parameter according to the first query type to obtain a converted context parameter includes: Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with the first character to obtain a converted context parameter according to the first query type and the second configuration information; or Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with a second character according to the first query type and the second configuration information to obtain a converted context parameter; or Acquire multiple parameter values in the context parameter, and merge the multiple parameter values in a target format according to the first query type and the second configuration information to obtain a converted context parameter, wherein the target format consists of the first character and the third character.
[0009] Optionally, the target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: Determine a second query type according to the second configuration information, and traverse the context parameters to obtain multiple parameter values according to the second query type; updating the second configuration information respectively according to the multiple parameter values, and initiating requests respectively according to the updated second configuration information and the authentication parameters to obtain multiple third response results; Merging the plurality of third response results to obtain a response result array, and parsing the response result array; A plurality of result attribute values are respectively extracted from the parsed response result array according to the second configuration information, and the plurality of result attribute values are combined to obtain a second query result.
[0010] Optionally, merging the second query result into the first query result to obtain a target query result includes: When the second query result is of the target type and the second configuration information includes the target character, obtaining a result attribute value in the second query result, and merging the result attribute value into the first query result; Another result attribute value in the second query result is obtained, and the another result attribute value is further merged into the first query result to obtain a target query result.
[0011] Optionally, merging the second query result into the first query result to obtain a target query result includes: When the second query result is of a target type but the second configuration information does not include a target character, the second query result is merged into the first query result to obtain a target query result, and the second query result includes a plurality of result attribute values.
[0012] According to a second aspect of an embodiment of the present disclosure, there is provided an aggregate query device, which is applied to an application gateway, and includes: A result interception module is configured to obtain first configuration information of the first aggregation, and intercept the first query result of the first aggregation according to the first configuration information; a parameter extraction module, configured to extract a target parameter from the first query result according to the first configuration information, and obtain second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation; The result merging model is configured to call the second configuration information according to the target parameter to obtain a second query result, and merge the second query result into the first query result to obtain a target query result.
[0013] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of any one of the aggregate query methods provided in the first aspect of the present disclosure are implemented.
[0014] According to a fourth aspect of an embodiment of the present disclosure, there is provided an electronic device, including: processor; a memory for storing processor-executable instructions; The processor is configured to: execute the executable instructions to implement the steps of any one of the aggregate query methods provided in the first aspect of the present disclosure.
[0015] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects: In the method and device provided by the exemplary embodiments of the present disclosure, on the one hand, the configuration of the first aggregation and the second aggregation is performed based on the application gateway, which greatly reduces the difficulty of implementing and maintaining cross-aggregation queries, and avoids the problem that the traditional method requires front-end or back-end development intervention. On the other hand, when the application gateway performs an aggregate query to determine the target query result, the original back-end microservices and the division and boundaries of the aggregation will not be affected, thereby ensuring the original aggregation isolation of the back-end and retaining the characteristics of high cohesion and low coupling between aggregations.
[0016] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0018] Figure 1 A schematic diagram of a process flow of an aggregate query method in an exemplary embodiment of the present disclosure is schematically shown; Figure 2 A schematic diagram schematically shows a flow chart of a method for generating a second query result in an exemplary embodiment of the present disclosure; Figure 3 A schematic diagram schematically shows a flow chart of another method for generating a second query result in an exemplary embodiment of the present disclosure; Figure 4 A schematic diagram of a process of converting context parameters according to a first query type in an exemplary embodiment of the present disclosure is schematically shown; Figure 5 A schematic diagram schematically shows a flow chart of another method for generating a second query result in an exemplary embodiment of the present disclosure; Figure 6 A schematic diagram schematically shows a flow chart of a method for generating a target query result in an exemplary embodiment of the present disclosure; Figure 7 The schematic diagram schematically shows the architecture of the aggregate query method in the application scenario in the exemplary embodiment of the present disclosure; Figure 8 A schematic diagram schematically illustrates a flow chart of a method for intercepting a main aggregate query in an application scenario in an exemplary embodiment of the present disclosure; Fig. 9A schematic diagram schematically illustrates a flow chart of a method for querying order records from aggregation in an application scenario in an exemplary embodiment of the present disclosure; Fig.10 A schematic diagram schematically illustrates a flow chart of a method for multi-record aggregate query in an application scenario in an exemplary embodiment of the present disclosure; Fig.11 A schematic diagram schematically illustrates a flow chart of a method for multi-record polling query in an application scenario in an exemplary embodiment of the present disclosure; Fig.12 A schematic diagram of the structure of an aggregate query device in an exemplary embodiment of the present disclosure is schematically shown; Fig.13 A schematic diagram schematically shows the structure of another aggregate query device in an exemplary embodiment of the present disclosure; Fig.14 The structural diagram of another aggregate query device in an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0019] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0020] It should be noted that all actions of acquiring signals, information or data in the present disclosure are carried out in compliance with the relevant data protection laws and policies of the country where the device is located and with the authorization given by the owner of the corresponding device.
[0021] In the design of microservice architecture based on DDD, in order to ensure the high cohesion and low coupling characteristics of the domain, the domain is broken down into different bounded contexts (i.e. microservices) and aggregations. However, when querying, sometimes it is necessary to face cross-service and cross-aggregate query assembly.
[0022] For example, when querying user information (primary aggregation) in the user microservice, it is also necessary to query the department information (secondary aggregation) of the department microservice based on the department ID (Identity document) in the user information to supplement the department code, department name and other information in the user information.
[0023] Currently, cross-service and cross-aggregation query assembly usually adopts three methods as shown in Table 1:
[0024] Table 1 It can be seen that when the front-end aggregation assembly query is adopted, although the isolation of the back-end aggregation is guaranteed, the workload and maintenance difficulty of the front-end are increased. When the back-end aggregation assembly-cross-aggregation query is adopted, although the isolation of the back-end aggregation is guaranteed, the workload and maintenance difficulty of the back-end aggregation conversion are increased. When the back-end aggregation assembly-lightweight CQRS query is adopted, although the implementation difficulty of the cross-aggregation query is reduced to a certain extent, it is only applicable to the cross-aggregation assembly query within the same microservice, because the main aggregation is too involved in the slave aggregation, the coupling is high, and the isolation between the aggregations is destroyed.
[0025] In view of the problems existing in the related technologies, the present invention provides an aggregate query method, which is applied to an application gateway. Figure 1 is a flowchart of an aggregate query method according to an exemplary embodiment. Figure 1 As shown, the method may at least include the following steps: Step S110. Obtain first configuration information of the first aggregation, and intercept the first query result of the first aggregation according to the first configuration information.
[0026] Step S120: Extract target parameters from the first query result according to the first configuration information, and obtain second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation.
[0027] Step S130: Call the second configuration information according to the target parameter to obtain a second query result, and merge the second query result into the first query result to obtain a target query result.
[0028] In the exemplary embodiments of the present disclosure, on the one hand, the configuration of the first aggregation and the second aggregation is performed based on the application gateway, which greatly reduces the difficulty of implementing and maintaining cross-aggregation queries and avoids the problem that the traditional method requires front-end or back-end development intervention. On the other hand, when the target query result is determined by performing aggregate query in the application gateway, the original back-end microservices and the division and boundaries of aggregations will not be affected, thereby ensuring the original aggregation isolation of the back-end and retaining the characteristics of high cohesion and low coupling between aggregations.
[0029] The following is a detailed description of each step of the aggregation query method.
[0030] In step S110, first configuration information of the first aggregation is obtained, and a first query result of the first aggregation is intercepted according to the first configuration information.
[0031] In the exemplary embodiments of the present disclosure, the basic concept of aggregation is to merge a group of related, smaller service calls into a larger, composite service call. This approach helps reduce the number of cross-service communications and communication overhead. When processing a user request requires multiple microservices to work together, using a service aggregation strategy is particularly effective.
[0032] For a gateway route (one route corresponds to a specific backend microservice), the first aggregation that needs to be assembled across aggregation queries can be configured.
[0033] Specifically, the first configuration information of the first aggregation is shown in Table 2:
[0034] Table 2 Furthermore, the first query result of the corresponding first aggregation is intercepted according to the uri (Uniform Resource Identifier) and method (specific method or function for performing the query operation) in the first configuration information of the first aggregation.
[0035] In step S120, target parameters are extracted from the first query result according to the first configuration information, and second configuration information of the second aggregation is obtained, where the second aggregation exists based on the first aggregation.
[0036] In an exemplary embodiment of the present disclosure, after obtaining the first configuration information, the context parameters can be extracted from the first query result of the first aggregation according to the contextParams (context parameters) in the first configuration information, and the corresponding request headers and cookies can be extracted respectively according to headersRelay (recording request header information) and cookiesRelay (a tool or service for recording and managing cookies (text files, usually containing fields such as name, value, domain name, path and expiration time)) in the first configuration information, so as to use the context parameters, request headers and cookies as target parameters.
[0037] Since the second aggregation is extended from the first aggregation, for the first configuration information of the first aggregation, a plurality of second configuration information of the second aggregation can be configured for the first aggregation.
[0038] Specifically, the second configuration information of the second aggregation is shown in Table 3:
[0039] Table 3 In step S130, the second configuration information is called according to the target parameter to obtain a second query result, and the second query result is merged into the first query result to obtain a target query result.
[0040] In an exemplary embodiment of the present disclosure, after acquiring the second configuration information, the second configuration information can be called using the target parameter to perform a second aggregate query. Specifically, the second aggregate query method includes a single record query and a multi-record batch query.
[0041] Among them, a single record query is a master aggregation information corresponding to a slave aggregation information, and the corresponding context parameter value in the slave aggregation URI is a single value.
[0042] A multi-record batch query is a master aggregation information corresponding to multiple slave aggregation information. In this case, the corresponding context parameter value in the slave aggregation URI is a multi-value array.
[0043] In an optional embodiment, the target parameters include: context parameters and authentication parameters; Figure 2 A flow chart of a method for generating a second query result is shown, such as Figure 2 As shown, the method may at least include the following steps: in step S210, the second configuration information is updated according to the context parameter, and a request is initiated according to the updated second configuration information and the authentication parameter to obtain a first response result.
[0044] The parameter placeholder {…} of the uri in the second configuration information is replaced with the specific parameter in the context parameter to update the second configuration information.
[0045] Furthermore, an HTTP (Hypertext Transfer Protocol) request call is initiated to the local gateway using the uri and method with replaced parameters, as well as the additional request headers and cookies set by headersRelay and cookiesRelay. The application gateway then forwards the HTTP call to the backend service, so that the HTTP request call obtains the first response result.
[0046] The authentication parameters include a request header and a cookie, and may also include other parameters with an authentication function according to actual conditions, which is not specifically limited in this exemplary embodiment.
[0047] In step S220, the first response result is parsed, and the second query result is extracted from the parsed first response result according to the second configuration information.
[0048] When parsing the first response result, the resultPath in the second configuration information is determined according to the JsonPath layer-by-layer addressing to extract the specific result attribute in the first response result as the second query result.
[0049] Further, the second query result is merged into the first query result according to the mergePath in the second configuration information to obtain the target query result.
[0050] In an optional embodiment, the target parameters include: context parameters and authentication parameters; Figure 3 A flow chart of another method for generating a second query result is shown. Figure 3 As shown, the method may at least include the following steps: In step S310, a first query type is determined according to second configuration information, and context parameters are converted according to the first query type to obtain converted context parameters.
[0051] The query type may be determined according to queryBatchType in the second configuration information. When queryBatchType is COMMA_AGGR, SPACE_AGGR or ARRAY_AGGR, the first query type may be determined, and the first query type may be an aggregate query type.
[0052] In an alternative embodiment, Figure 4 A flow chart of a method for converting context parameters according to a first query type is shown, such as Figure 4 As shown, the method may at least include the following steps: in step S410, multiple parameter values in the context parameter are obtained, and the converted context parameter is obtained by combining the multiple parameter values with the first character according to the first query type and the second configuration information.
[0053] For multi-record batch queries, the context parameter includes a multi-value array, so multiple parameter values can be obtained.
[0054] Further, when the queryBatchType in the second configuration information is COMMA_AGGR, the merged parameter values may be separated by commas to serve as converted context parameters.
[0055] In step S420, multiple parameter values in the context parameter are obtained, and the multiple parameter values are combined with the second character according to the first query type and the second configuration information to obtain the converted context parameter.
[0056] For multi-record batch queries, the context parameter includes a multi-value array, so multiple parameter values can be obtained.
[0057] Further, when queryBatchType in the second configuration information is SPACE_AGGR, the merged parameter values may be separated by spaces to serve as converted context parameters.
[0058] In step S430, multiple parameter values in the context parameter are obtained, and the multiple parameter values are merged in a target format according to the first query type and the second configuration information to obtain a converted context parameter, where the target format consists of the first character and the third character.
[0059] For multi-record batch queries, the context parameter includes a multi-value array, so multiple parameter values can be obtained.
[0060] Further, when the queryBatchType in the second configuration information is ARRAY_AGGR, the merged parameter values may be displayed in an array format as the converted context parameter, and the array format is separated by commas and square brackets.
[0061] In step S320, the second configuration information is updated according to the converted context parameters, and a request is initiated according to the updated second configuration information and the authentication parameters to obtain a second response result.
[0062] After obtaining the converted context parameters, the converted context parameters may be used to replace the parameter placeholder {…} of the URI in the second configuration information to update the second configuration information.
[0063] Furthermore, an HTTP request call is initiated to the local gateway using the uri and method with replaced parameters, as well as the additional request headers and cookies set by headersRelay and cookiesRelay. The application gateway then forwards the HTTP call to the backend service, so that the HTTP request call obtains a second response result.
[0064] In step S330, the second response result is parsed, and a second query result is extracted from the parsed second response result according to the second configuration information.
[0065] When parsing the second response result, the resultPath in the second configuration information is determined according to the JsonPath layer-by-layer addressing to extract the specific result attribute in the second response result as the second query result.
[0066] In an optional embodiment, the target parameters include: context parameters and authentication parameters; Figure 5 A flow chart of another method for generating a second query result is shown. Figure 5 As shown, the method may at least include the following steps: in step S510, a second query type is determined according to second configuration information, and context parameters are traversed according to the second query type to obtain multiple parameter values.
[0067] The query type may be determined according to queryBatchType in the second configuration information. When queryBatchType is ROUDN_ROBIN, the second query type may be determined, and the second query type may be a polling query type.
[0068] Furthermore, each item in the multi-value array constituting the context parameter is traversed in turn to obtain corresponding multiple parameter values.
[0069] In step S520, the second configuration information is updated according to the multiple parameter values, and requests are initiated according to the updated second configuration information and the authentication parameters to obtain multiple third response results.
[0070] For multiple parameter values, each of them can be used to replace the parameter placeholder {…} of the URI in the second configuration information to update the second configuration information. That is, each item in the multi-value array will generate a URI, and multiple different generated URIs can be returned.
[0071] For multiple different URIs and corresponding methods, as well as additional request headers and cookies set by headersRelay and cookiesRelay, HTTP request calls are initiated to the local gateway respectively, and then the application gateway forwards the HTTP call to the backend service, so that the HTTP request call obtains the third response result. In other words, each URI will initiate an HTTP request call separately.
[0072] In step S530, a plurality of third response results are merged to obtain a response result array, and the response result array is parsed.
[0073] After completing multiple request calls and obtaining multiple third response results, the multiple third response results can be merged in sequence to obtain a response result array, so as to parse the response result array by addressing layer by layer according to JsonPath.
[0074] In step S540, a plurality of result attribute values are respectively extracted from the parsed response result array according to the second configuration information, and the plurality of result attribute values are combined to obtain a second query result.
[0075] Furthermore, the response result array is traversed, and a specific result attribute value in each item is extracted according to the resultPath in the second configuration information, and multiple result attribute values are merged to obtain the second query result.
[0076] In an alternative embodiment, Figure 6 A flow chart of a method for generating a target query result is shown, Figure 6As shown, the method may include at least the following steps: In step S610, when the second query result is of the target type and the second configuration information includes the target character, a result attribute value in the second query result is obtained, and the result attribute value is merged into the first query result.
[0077] When the second query result is of array type and the second configuration information includes [*], the first result attribute value in the second query result to be merged can be merged into the first item in mergPath in sequence.
[0078] It is worth noting that, since when the query type is a polling query type, the second query result is an array type, therefore, when the query type is a polling query type, it is not necessary to determine the type of the second query result.
[0079] In step S620, another result attribute value in the second query result is obtained, and the other result attribute value is further merged into the first query result to obtain the target query result.
[0080] Furthermore, the second result attribute values in the second query result are obtained in sequence, and the result attribute values are merged into the first query result in order, and finally the merging is completed to obtain the target query result.
[0081] In an optional embodiment, when the second query result is of a target type but the second configuration information does not include a target character, the second query result is merged into the first query result to obtain a target query result, and the second query result includes a plurality of result attribute values.
[0082] When the second query result is of array type but the second configuration information does not contain [*], multiple result attribute values in the second query result are merged into the first query result as one item to obtain the target query result.
[0083] The following is a detailed description of the aggregate query method in the embodiment of the present disclosure in conjunction with an application scenario.
[0084] In the application scenario, an implementation of cross-aggregation query assembly based on application gateway is proposed.
[0085] Specifically, based on the HTTP application gateway (Spring Cloud Gateway, supporting REST (Representational State Transfer) / JSON (JavaScript Object Notation) requests), the application gateway uniformly forwards the requests (REST, JSON) of multiple backend microservices, and completes the cross-aggregate query assembly according to the corresponding cross-aggregate query assembly configuration. This gateway-based and configured approach not only reduces the difficulty of implementing and maintaining cross-aggregate query assembly, but also ensures the original aggregation isolation of the backend.
[0086] Figure 7 The schematic diagram of the architecture of the aggregate query method in the application scenario is shown as follows: Figure 7 As shown in the figure, the architecture is mainly divided into two modules, namely cross-aggregation query assembly configuration and cross-aggregation query assembly filter.
[0087] Among them, the cross-aggregation query assembly configuration defines how to define the rules for cross-aggregation query assembly through configuration. Specifically, the configuration content is mainly divided into two parts, namely the main aggregation query configuration and the slave aggregation query configuration.
[0088] For a certain gateway route, the main aggregation query interface that needs to be assembled across aggregation queries can be intercepted. The subsequent filter module will intercept the corresponding main aggregation query response result according to the main aggregation configuration uri and method, and extract context parameters from the main aggregation response result according to the configuration contextParams, and record the corresponding request headers and cookies according to headersRelay and cookiesRelay for subsequent slave aggregation queries. The content of the main aggregation query configuration is shown in Table 2 and will not be repeated here.
[0089] For a main aggregation query configuration, multiple slave aggregation query configurations can be configured for it. After receiving the main aggregation query result, the subsequent filter module calls multiple slave aggregation query interfaces (uri, method) according to the context parameters extracted from the main aggregation configuration, and merges the query results (resultPath) of the slave aggregation into the query results (mergePath) of the main aggregation. In the case of batch query slave aggregation, for example, there are multiple role IDs in the user information, and the role information needs to be queried in batches. The configuration (queryBatchType) supports polling or aggregation query. Among them, polling query means querying one at a time and multiple times; aggregation query is to query all at once. The content of a single slave aggregation query configuration is shown in Table 3, which will not be repeated here.
[0090] For example, a user details cross-aggregation query assembly configuration example could be: YAML spring: cloud: gateway: routes: # Routing -id: rbac uri: http: / / localhost:8081 predicates: - Path= / rbac / ** # Filters filters: - StripPrefix=1 # Cross-aggregation query assembly configuration - User details -name: Aggr args: # Main Aggregation Query Configuration - User Information uri: / rbac / api / v1 / users / {id} method: GET headersRelay: Authorization contextParams: deptId: $.data.deptId roleId: $.data.roles[*].id # Multiple slave aggregation query configurations Steps: # From the aggregation query configuration 1 - department information - uri: / rbac / api / v1 / depts / {deptId} method: GET resultPath: $.data mergePath: $.data.dept_aggr_sq resultMerge: - resultPath: $.data.deptName mergePath: $.data.deptName_aggr_sq - resultPath: $.data.deptCode mergePath: $.data.deptCode_aggr_sq # Query Configuration 2 from Aggregation - Role Information - uri: / rbac / api / v1 / roles / {roleId} method: GET # Batch query type (polling, comma separated, space separated, array format) queryBatchType: ROUND_ROBIN # Batch query result merging resultMerge: - resultPath: $.data.roleCode mergePath: $.data.roles[*].roleCode_aggr_rb - resultPath: $.data mergePath: $.data.roles_aggr_rb # Query configuration 3 from aggregation - role information - uri: / rbac / api / v1 / roles / batch / {roleId} method: GET # Batch query type (polling, comma separated, space separated, array format) queryBatchType: COMMA_AGGR # Batch query result merging resultMerge: - resultPath: $.data[*].roleCode mergePath: $.data.roles[*].roleCode_aggr_ca - resultPath: $.data mergePath: $.data.roles_aggr_ca An example of user paginated list cross-aggregation query assembly configuration could be: YAML spring: cloud: gateway: routes: # Routing -id: rbac uri: http: / / localhost:8081 predicates: - Path= / rbac / ** # Filters filters: - StripPrefix=1 # Cross-aggregation query assembly configuration - user paging list -name: Aggr args: # Main Aggregation Query Configuration - User Pagination List uri: / rbac / api / v1 / users method: GET headersRelay: Authorization contextParams: deptId: $.data.list[*].deptId # Multiple slave aggregation query configurations Steps: # From the aggregation query configuration 1 - department information - uri: / rbac / api / v1 / depts / {deptId} method: GET # Batch query type (polling, comma separated, space separated, array format) queryBatchType: ROUND_ROBIN # Batch query result merging resultMerge: - resultPath: $.data.deptName mergePath: $.data.list[*].deptName_aggr_rb - resultPath: $.data.deptCode mergePath: $.data.list[*].deptCode_aggr_rb - resultPath: $.data mergePath: $.data.dept_aggr_rb The cross-aggregation query assembly filter is a specific implementation of the cross-aggregation query assembly. It parses the rules in the cross-aggregation query assembly configuration and completes cross-service and cross-aggregation query calls and assembly in the form of a gateway filter.
[0091] Specifically, the implementation steps of the cross-aggregation query assembly filter include intercepting the main aggregation query and the sub-aggregation query and assembling.
[0092] Figure 8 A flow chart of a method for intercepting a main aggregate query in an application scenario is shown, such as Figure 8 As shown, in step S810, the main aggregate query response result is intercepted.
[0093] Intercept the corresponding main aggregation query response result according to the main aggregation query configuration (uri, method).
[0094] In step S820, context parameters are extracted.
[0095] Extract context parameters from the main aggregation response result according to the configuration contextParams.
[0096] In step S830, the request header is extracted.
[0097] Record the corresponding request headers according to headersRelay.
[0098] In step S840, the cookie is extracted.
[0099] Record the corresponding cookies according to cookiesRelay.
[0100] Sub-aggregate query and assembly is to call the sub-aggregate query interface (uri, method) in sequence according to the sub-aggregate query configuration, and complete the assembly of the sub-aggregate query results. Specifically, the sub-aggregate query can be divided into 3 ways.
[0101] Among them, a single-record slave aggregation query means that one main aggregation information corresponds to one slave aggregation information. At this time, the corresponding context parameter value in the slave aggregation URI is a single value.
[0102] Multi-record slave aggregation batch query means that one master aggregation information corresponds to multiple slave aggregation information. In this case, the corresponding context parameter value in the slave aggregation URI is a multi-value array.
[0103] Among them, the multi-record batch query from aggregation includes two types: multi-record batch query from aggregation using aggregation query and multi-record batch query from aggregation using polling.
[0104] Fig. 9 The flowchart of the method of querying order records from aggregation in the application scenario is shown as follows: Fig. 9 As shown, in step S910, the context parameter in the uri is replaced.
[0105] Replace the parameter placeholders {...} in the uri with the specific parameter values in the context parameter.
[0106] In step S920, a local gateway HTTP call is initiated.
[0107] Use the uri and method with replaced parameters, and carry the additional request headers and cookies set by headersRelay and cookiesRelay to initiate an HTTP call to the local gateway.
[0108] In step S930, the backend HTTP call is forwarded.
[0109] Furthermore, the local gateway forwards the HTTP request call to the backend service.
[0110] In step S940, the result attributes are extracted.
[0111] Parse the response result and extract specific result attributes from the aggregate query response result according to the configured resultPath.
[0112] In step S950, the result attributes are merged.
[0113] Merges specific result attribute values into the main aggregate query response result according to the configured mergePath.
[0114] Fig.10 A flow chart of a method for multi-record aggregate query in an application scenario is shown, such as Fig.10 As shown, in step S1010, the parameter values are merged to replace the context parameters in the uri.
[0115] According to the batch query type, the multi-value array parameters in the context parameters are converted into merged parameter values, which can be comma-separated, space-separated, or merged into an array format. Furthermore, the merged parameter values are used to replace the parameter placeholder {...} in the uri.
[0116] In step S1020, a local gateway HTTP call is initiated.
[0117] Use the uri and method with replaced parameters, and carry the additional request headers and cookies set by headersRelay and cookiesRelay to initiate an HTTP request call to the local gateway.
[0118] In step S1030, the backend HTTP call is forwarded.
[0119] The local gateway then forwards the HTTP call to the backend service.
[0120] In step S1040, the result attributes are extracted.
[0121] Parse the response result and extract specific result attributes from the aggregate query response result according to the configured resultPath.
[0122] In step S1050, the result attributes are merged, and support is provided to merge to the nth item in sequence.
[0123] Merge the specific result attribute value into the main aggregate query response result according to the configured mergePath. If the specific result attribute to be merged is an array type and mergePath contains [*], then the nth item in the result attribute array to be merged is merged into the [nth] item in mergPath.
[0124] For example, the result attribute extracted through resultPath is the role code array [role0, role1, role2], and mergePath is $.data.roles[*].roleCode, then role0 is merged into $.data.roles[0].roleCode, role1 is merged into $.data.roles[1].roleCode, and so on.
[0125] Fig.11 A flow chart of a method for multi-record polling query in an application scenario is shown, such as Fig.11 As shown, in step S1110, multiple URIs are generated according to the context parameter value array.
[0126] Iterate through each item in the multi-value array of context parameters in turn, and use each item to replace the parameter placeholder {...} in the uri. Each item in the multi-value array will generate a uri, so multiple different uris will be returned.
[0127] In step S1120, local gateway HTTP calls (multiple HTTP calls) are initiated for multiple URIs respectively.
[0128] For multiple different URIs and their associated methods, HTTP requests are initiated to the local gateway with the additional request headers and cookies set by headersRelay and cookiesRelay. Each URI will initiate an HTTP request call separately.
[0129] In step S1130, the backend HTTP call is forwarded.
[0130] The gateway then forwards the HTTP call to the backend service.
[0131] In step S1140, multiple response results are merged into an array.
[0132] After completing multiple HTTP request calls, multiple response results are merged into a response result array in sequence.
[0133] In step S1150, the result attribute array is extracted.
[0134] Traverse the response result array, extract specific result attributes from each item in the response result array according to the configured resultPath, and merge the specific result attributes corresponding to each item into a new result attribute array.
[0135] In step S1160, the result attribute arrays are merged, and support is provided to merge to the nth item in sequence.
[0136] Merge the new result attribute array into the main aggregate query response result according to the configured mergePath. If mergePath contains [*], the nth item in the result attribute array to be merged will be merged into the [nth] item in mergPath.
[0137] For example, the result attribute extracted through resultPath is the role code array [role0, role1, role2], and mergePath is $.data.roles[*].roleCode, then role0 is merged into $.data.roles[0].roleCode, role1 is merged into $.data.roles[1].roleCode, and so on.
[0138] In an exemplary embodiment of the present disclosure, the cross-aggregation query assembly configuration module defines the rules for cross-aggregation query assembly in the form of gateway configuration. Based on the HTTP application gateway (Spring Cloud Gateway, supporting REST / JSON requests), the application gateway uniformly forwards the requests (REST, JSON) of multiple backend microservices, and the application gateway can complete the cross-aggregation query assembly according to the corresponding cross-aggregation query assembly configuration. This gateway-based and configured approach greatly reduces the difficulty of implementing and maintaining cross-aggregation query assembly, and avoids the problem that the traditional approach requires intervention through front-end or back-end development.
[0139] The cross-aggregation query assembly filter module automatically completes the cross-aggregation query assembly according to the configuration. The cross-aggregation query assembly occurs at the gateway layer, that is, the cross-aggregation query assembly filter in the gateway automatically completes the cross-aggregation query assembly according to the configuration. In this way, the original backend microservices, aggregation divisions and boundaries are not affected, ensuring the original aggregation isolation of the backend and retaining the characteristics of high cohesion and low coupling between aggregations.
[0140] In addition, in an exemplary embodiment of the present disclosure, an aggregate query device is also provided, which is applied to an application gateway. Fig.12 A schematic diagram of the structure of the aggregate query device is shown. Fig.12 As shown, the aggregate query device 1200 may include: a result interception module 1210, a parameter extraction module 1220 and a result merging model 1230. Among them: A result interception module 1210 is configured to obtain first configuration information of a first aggregation, and intercept a first query result of the first aggregation according to the first configuration information; A parameter extraction module 1220 is configured to extract a target parameter from the first query result according to the first configuration information, and obtain second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation; The result merging model 1230 is configured to call the second configuration information according to the target parameter to obtain a second query result, and merge the second query result into the first query result to obtain a target query result.
[0141] In some embodiments of the present disclosure, the target parameters include: context parameters and authentication parameters; The result merging model 1230 is configured as follows: updating the second configuration information according to the context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a first response result; The first response result is parsed, and a second query result is extracted from the parsed first response result according to the second configuration information.
[0142] In some embodiments of the present disclosure, the target parameters include: context parameters and authentication parameters; The result merging model 1230 is configured as follows: determining a first query type according to the second configuration information, and converting the context parameter according to the first query type to obtain a converted context parameter; updating the second configuration information according to the converted context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a second response result; The second response result is parsed, and a second query result is extracted from the parsed second response result according to the second configuration information.
[0143] In some embodiments of the present disclosure, the result merging model 1230 is configured as follows: Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with the first character to obtain a converted context parameter according to the first query type and the second configuration information; or Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with a second character according to the first query type and the second configuration information to obtain a converted context parameter; or Acquire multiple parameter values in the context parameter, and merge the multiple parameter values in a target format according to the first query type and the second configuration information to obtain a converted context parameter, wherein the target format consists of the first character and the third character.
[0144] In some embodiments of the present disclosure, the target parameters include: context parameters and authentication parameters; The result merging model 1230 is configured as follows: Determine a second query type according to the second configuration information, and traverse the context parameters to obtain multiple parameter values according to the second query type; updating the second configuration information respectively according to the multiple parameter values, and initiating requests respectively according to the updated second configuration information and the authentication parameters to obtain multiple third response results; Merging the plurality of third response results to obtain a response result array, and parsing the response result array; A plurality of result attribute values are respectively extracted from the parsed response result array according to the second configuration information, and the plurality of result attribute values are combined to obtain a second query result.
[0145] In some embodiments of the present disclosure, the result merging model 1230 is configured as follows: When the second query result is of the target type and the second configuration information includes the target character, obtaining a result attribute value in the second query result, and merging the result attribute value into the first query result; Another result attribute value in the second query result is obtained, and the another result attribute value is further merged into the first query result to obtain a target query result.
[0146] In some embodiments of the present disclosure, the result merging model 1230 is configured as follows: When the second query result is of a target type but the second configuration information does not include a target character, the second query result is merged into the first query result to obtain a target query result, and the second query result includes a plurality of result attribute values.
[0147] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0148] The present disclosure also provides a computer-readable storage medium having computer program instructions stored thereon, which implement the steps of the aggregate query method provided by the present disclosure when the program instructions are executed by a processor.
[0149] Fig.13 1 is a block diagram of another apparatus 1300 for aggregate query according to an exemplary embodiment. For example, the apparatus 1300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0150] Reference Fig.13 , the device 1300 may include one or more of the following components: a processing component 1302 , a memory 1304 , a power component 1306 , a multimedia component 1308 , an audio component 1310 , an input / output interface 1312 , a sensor component 1314 , and a communication component 1316 .
[0151] The processing component 1302 generally controls the overall operation of the device 1300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 1302 may include one or more processors 1320 to execute instructions to complete all or part of the steps of the above method. In addition, the processing component 1302 may include one or more modules to facilitate the interaction between the processing component 1302 and other components. For example, the processing component 1302 may include a multimedia module to facilitate the interaction between the multimedia component 1308 and the processing component 1302.
[0152] The memory 1304 is configured to store various types of data to support the operation of the device 1300. Examples of such data include instructions for any application or method operating on the device 1300, contact data, phone book data, messages, pictures, videos, etc. The memory 1304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0153] The power supply component 1306 provides power to the various components of the device 1300. The power supply component 1306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 1300.
[0154] The multimedia component 1308 includes a screen that provides an output interface between the device 1300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1308 includes a front camera and / or a rear camera. When the device 1300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0155] The audio component 1310 is configured to output and / or input audio signals. For example, the audio component 1310 includes a microphone (MIC), and when the device 1300 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 1304 or sent via the communication component 1316. In some embodiments, the audio component 1310 also includes a speaker for outputting audio signals.
[0156] The input / output interface 1312 provides an interface between the processing component 1302 and the peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0157] The sensor assembly 1314 includes one or more sensors for providing various aspects of the status assessment of the device 1300. For example, the sensor assembly 1314 can detect the open / closed state of the device 1300, the relative positioning of components, such as the display and keypad of the device 1300, the sensor assembly 1314 can also detect the position change of the device 1300 or a component of the device 1300, the presence or absence of user contact with the device 1300, the orientation or acceleration / deceleration of the device 1300, and the temperature change of the device 1300. The sensor assembly 1314 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 1314 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1314 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0158] The communication component 1316 is configured to facilitate wired or wireless communication between the device 1300 and other devices. The device 1300 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 1316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0159] In an exemplary embodiment, the apparatus 1300 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0160] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1304 including instructions, and the instructions can be executed by the processor 1320 of the device 1300 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0161] In addition to being an independent electronic device, the above-mentioned device can also be a part of an independent electronic device. For example, in one embodiment, the device can be an integrated circuit (IC) or a chip, wherein the integrated circuit can be an IC or a collection of multiple ICs; the chip can include but is not limited to the following types: GPU (Graphics Processing Unit), CPU (Central Processing Unit), FPGA (Field Programmable Gate Array), DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), SOC (System on Chip, SoC), etc. The above-mentioned integrated circuit or chip can be used to execute executable instructions (or codes) to implement the above-mentioned aggregate query method. The executable instructions can be stored in the integrated circuit or chip, or can be obtained from other devices or equipment, for example, the integrated circuit or chip includes a processor, a memory, and an interface for communicating with other devices. The executable instruction can be stored in the memory, and when the executable instruction is executed by the processor, the above-mentioned aggregate query method is implemented; alternatively, the integrated circuit or chip can receive the executable instruction through the interface and transmit it to the processor for execution, so as to implement the above-mentioned method.
[0162] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above-mentioned aggregate query method when executed by the programmable device.
[0163] Fig.14 1 is a block diagram of another apparatus 1400 for aggregate query according to an exemplary embodiment. For example, the apparatus 1400 may be provided as a server. Fig.14 The apparatus 1400 includes a processing component 1422, which further includes one or more processors, and a memory resource represented by a memory 1432 for storing instructions, such as an application, that can be executed by the processing component 1422. The application stored in the memory 1432 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1422 is configured to execute instructions to perform the above-mentioned aggregate query method.
[0164] The device 1400 may also include a power supply component 1426 configured to perform power management of the device 1400, a wired or wireless network interface 1450 configured to connect the device 1400 to a network, and an input / output interface 1458. The device 1400 may operate based on an operating system stored in the memory 1432.
[0165] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0166] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An aggregate query method, characterized in that: Applied to application gateways, including: Obtaining first configuration information of the first aggregation, and intercepting a first query result of the first aggregation according to the first configuration information; Extracting target parameters from the first query result according to the first configuration information, and acquiring second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation; The second configuration information is called according to the target parameter to obtain a second query result, and the second query result is merged into the first query result to obtain a target query result.
2. The aggregate query method according to claim 1, characterized in that: The target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: updating the second configuration information according to the context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a first response result; The first response result is parsed, and a second query result is extracted from the parsed first response result according to the second configuration information.
3. The aggregate query method according to claim 1, characterized in that: The target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: determining a first query type according to the second configuration information, and converting the context parameter according to the first query type to obtain a converted context parameter; updating the second configuration information according to the converted context parameter, and initiating a request according to the updated second configuration information and the authentication parameter to obtain a second response result; The second response result is parsed, and a second query result is extracted from the parsed second response result according to the second configuration information.
4. The aggregate query method according to claim 3, characterized in that: The converting the context parameter according to the first query type to obtain the converted context parameter includes: Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with the first character to obtain a converted context parameter according to the first query type and the second configuration information; or Acquire multiple parameter values in the context parameter, and combine the multiple parameter values with a second character according to the first query type and the second configuration information to obtain a converted context parameter; or Acquire multiple parameter values in the context parameter, and merge the multiple parameter values in a target format according to the first query type and the second configuration information to obtain a converted context parameter, wherein the target format consists of the first character and the third character.
5. The aggregate query method according to claim 1, characterized in that: The target parameters include: context parameters and authentication parameters; The calling the second configuration information according to the target parameter to obtain a second query result includes: Determine a second query type according to the second configuration information, and traverse the context parameters to obtain multiple parameter values according to the second query type; updating the second configuration information respectively according to the multiple parameter values, and initiating requests respectively according to the updated second configuration information and the authentication parameters to obtain multiple third response results; Merging the plurality of third response results to obtain a response result array, and parsing the response result array; A plurality of result attribute values are respectively extracted from the parsed response result array according to the second configuration information, and the plurality of result attribute values are combined to obtain a second query result.
6. The aggregate query method according to claim 3 or 5, characterized in that: The step of merging the second query result into the first query result to obtain a target query result includes: When the second query result is of the target type and the second configuration information includes the target character, obtaining a result attribute value in the second query result, and merging the result attribute value into the first query result; Another result attribute value in the second query result is obtained, and the another result attribute value is further merged into the first query result to obtain a target query result.
7. The aggregate query method according to claim 3 or 5, characterized in that: The step of merging the second query result into the first query result to obtain a target query result includes: When the second query result is of a target type but the second configuration information does not include a target character, the second query result is merged into the first query result to obtain a target query result, and the second query result includes a plurality of result attribute values.
8. An aggregate query device, characterized in that: Applied to application gateways, including: A result interception module is configured to obtain first configuration information of the first aggregation, and intercept the first query result of the first aggregation according to the first configuration information; a parameter extraction module, configured to extract a target parameter from the first query result according to the first configuration information, and obtain second configuration information of a second aggregation, where the second aggregation exists based on the first aggregation; The result merging model is configured to call the second configuration information according to the target parameter to obtain a second query result, and merge the second query result into the first query result to obtain a target query result.
9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
10. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 7.