Service request processing method and apparatus
By configuring service cluster information in the microservice gateway and using sentinel for computation, intelligent routing, load balancing, and dynamic rate limiting of service requests are achieved, solving the problem of rudimentary functions of existing microservice gateways and improving the scalability and security of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING PACTERA JINXIN TECH LTD
- Filing Date
- 2024-10-25
- Publication Date
- 2026-08-04
AI Technical Summary
In distributed systems based on microservice architecture, service request processing, cross-domain request processing, and authentication are complex and difficult to refactor. The default functions of existing microservice gateways are rudimentary, requiring developers to customize gateway filters, which increases the learning and implementation costs.
By pre-configuring the service cluster's configuration information in the database, the microservice gateway dynamically obtains this information, performs calculations using a specified service middleware such as Sentinel, sequentially traverses the filters of the processing nodes, and performs intelligent routing, load balancing, dynamic rate limiting, or circuit breaking filtering of service requests based on the calculation results, ensuring the flexibility and accuracy of the processing logic.
It improves the system's scalability, flexibility, and security, reduces system coupling, simplifies the management and maintenance of service clusters, and enhances the user experience.
Smart Images

Figure CN119420794B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of Internet technology, and in particular to a service request processing method and apparatus. Background Technology
[0002] With the widespread adoption of microservice architecture, the number of service nodes in distributed systems built on this architecture has increased and they are deployed independently. Direct client interaction with service nodes presents challenges such as increased request complexity, complex cross-domain request handling, complex authentication, and difficulty in refactoring. Introducing a microservice gateway as a unified entry point to process service requests simplifies client-service node interaction and improves system security, reliability, and maintainability. Therefore, understanding how to use a microservice gateway to process service requests is crucial. Summary of the Invention
[0003] This disclosure provides a service request processing method and apparatus to at least partially solve one of the technical problems in the related art. The technical solution of this disclosure is as follows:
[0004] According to a first aspect of the present disclosure, a service request processing method is provided, comprising: obtaining service configuration information associated with a service cluster from a database; in response to receiving a service request sent by a client, using a designated service middleware in the microservice gateway to calculate the service request according to the service configuration information to obtain a calculation result; and processing the service request according to the calculation result using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0005] According to a second aspect of the present disclosure, a service request processing apparatus is provided, comprising: an acquisition module, configured to acquire service configuration information associated with a service cluster from a database; a calculation module, configured to, in response to receiving a service request sent by a client, perform calculations on the service request based on the service configuration information using a specified service middleware in the microservice gateway to obtain a calculation result; and a processing module, configured to process the service request based on the calculation result using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0006] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the service request processing method as described in the first aspect of the present disclosure.
[0007] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform a service request processing method as described in the first aspect of the present disclosure.
[0008] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising: a computer program that, when executed by a processor, implements the service request processing method as described in the first aspect of the present disclosure.
[0009] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects: In this technical solution, by pre-configuring service configuration information associated with the service cluster in the database, the microservice gateway dynamically retrieves the service configuration information associated with the service cluster from the database, avoiding the problem of non-persistent service configuration information. When a service request is received from a client, the microservice gateway uses a designated service middleware to calculate the service request based on the service configuration information, obtains the calculation result, and processes the service request through filters in the request processing chain according to the calculation result. This achieves intelligent routing, load balancing, dynamic rate limiting, or circuit breaking filtering of service requests, improving the system's scalability, flexibility, and security, while reducing the system's coupling and making the management and maintenance of the service cluster more efficient. Specifically, when the microservice gateway uses the designated service middleware to calculate the request based on the service configuration information, it iterates through the configuration sub-information associated with multiple processing nodes, dynamically adjusting the processing logic according to actual needs. When the filter switch state indicated by the currently traversed processing node is on, the processing logic is dynamically adjusted. Furthermore, the system obtains the configuration parameters of the node and parses the service request to verify whether the actual value of the configuration parameter meets the corresponding parameter conditions. If all relevant parameters meet the conditions, the system selects the filter indicated by the current processing node to process the service request. This not only improves the system's flexibility and scalability but also ensures that the service request can be processed accurately and effectively according to predetermined rules and conditions, thus improving the user experience. In addition, when processing the service request through the filter in the request processing chain based on the calculation results, at least one processing parameter corresponding to the indicated filter is obtained from the service configuration information according to the filter indicated by the calculation results. The service request is then parsed using the indicated filter to obtain the parameter value of at least one processing parameter. The service request is then processed using the indicated filter based on the parameter value of at least one processing parameter. This realizes the processing of the corresponding processing parameters according to the processing logic corresponding to the filter, improving the flexibility and accuracy of service request processing.
[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0011] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0012] Figure 1 This is a flowchart illustrating the service request processing method shown in the first embodiment of this disclosure; Figure 2 This is a flowchart illustrating the service request processing method shown in the second embodiment of this disclosure; Figure 3 This is a flowchart illustrating the service request processing method shown in the third embodiment of this disclosure; Figure 4 This is a schematic diagram illustrating the principle of the request processing chain shown in the embodiments of this disclosure; Figure 5 This is a flowchart illustrating the service request processing method shown in the fourth embodiment of this disclosure; Figure 6(A) is a schematic diagram of a portion of the multiple service configuration tables shown in an embodiment of this disclosure; Figure 6(B) is another schematic diagram of the multiple service configuration tables shown in the embodiments of this disclosure; Figure 7 This is a flowchart illustrating the service request processing method shown in the fifth embodiment of this disclosure; Figure 8 This is a schematic diagram of the network topology of the network system where the microservice gateway is located, as shown in the embodiments of this disclosure; Figure 9 This is a schematic diagram of the service request processing apparatus shown in the sixth embodiment of this disclosure; Figure 10 This is a schematic diagram of the structure of an electronic device shown in an exemplary embodiment of the present disclosure. Detailed Implementation
[0013] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0014] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0015] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solution disclosed herein are all carried out with the consent of the user, and all comply with the provisions of relevant laws and regulations, and do not violate public order and good morals.
[0016] In microservice development, gateways are frequently needed for load balancing, rate limiting, and circuit breaking of backend application services. For example, Spring Cloud (a microservice architecture) provides a default gateway that implements rate limiting through a built-in rate-limiting filter (RequestRateLimiter), uses a token bucket algorithm, and leverages a Redis server to store intermediate data. For circuit breaking, it can be implemented using Hystrix (an open-source fault tolerance framework) by default. However, the default functionality provided by Spring Cloud is rather rudimentary; to meet the needs of different project scenarios, developers need to customize the gateway filter.
[0017] For rate limiting and circuit breaking of service requests, for example, the open-source framework Sentinel (an open-source service middleware) can be used to implement rate limiting and circuit breaking of service requests. However, the open-source Sentinel does not provide configuration saving, and the default gateway provided by Spring Cloud does not provide a component for integration with Sentinel. Relevant developers need to complete the integration according to the relevant Sentinel technical documentation, which increases the learning and implementation costs.
[0018] Therefore, in order to address the above problems, this disclosure proposes a service request processing method and apparatus.
[0019] The service request processing method and apparatus of this disclosure are described below with reference to the accompanying drawings.
[0020] Figure 1 This is a flowchart illustrating the service request processing method shown in the first embodiment of this disclosure. It should be noted that this embodiment is applied to a microservice gateway.
[0021] like Figure 1 As shown, the service request processing method includes the following steps: Step 101: Retrieve service configuration information associated with the service cluster from the database.
[0022] To avoid the problem of non-persistent service configuration information, as an example, service configuration information associated with the service cluster is pre-configured in the database. The microservice gateway retrieves the service configuration information from the database and stores it in the microservice gateway's memory.
[0023] Step 102: In response to receiving a service request from the client, the specified service middleware in the microservice gateway is used to calculate the service request based on the service configuration information to obtain the calculation result.
[0024] To reduce development costs, in this embodiment of the disclosure, the service middleware is specified as an open-source service middleware, for example, sentinel.
[0025] It's important to understand that microservice gateways include various types of filters, such as authentication filters, rate limiting filters, circuit breaker filters, and log filters. Each filter corresponds to a processing node in the request processing chain. Before processing a service request using the filter indicated by the processing node, a designated middleware performs calculations based on service configuration information to determine whether to apply the filter indicated by the corresponding processing node. Therefore, when a microservice gateway receives a service request from a client, it calculates the request based on the service configuration information to determine the appropriate filter to apply to the request.
[0026] Step 103: Based on the calculation results, process the service request using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0027] To achieve intelligent routing, load balancing, dynamic rate limiting, or circuit breaking of service requests, as an example, service requests are processed based on filters indicated by calculation results and the corresponding processing parameters. It should be noted that different filters have different processing parameters.
[0028] In summary, by pre-configuring service configuration information associated with the service cluster in the database, the microservice gateway dynamically retrieves this information, avoiding the problem of non-persistent service configuration information. When a service request is received from a client, the microservice gateway uses a designated service middleware to calculate the service request based on the service configuration information, obtains the calculation result, and processes the service request through filters in the request processing chain. This achieves intelligent routing, load balancing, dynamic rate limiting, or circuit breaking filtering of service requests, improving the system's scalability, flexibility, and security, while reducing system coupling and making the management and maintenance of the service cluster more efficient.
[0029] To clearly illustrate how the above embodiments use a designated service middleware in a microservice gateway to calculate service requests based on service configuration information to obtain calculation results, this disclosure proposes another service request processing method.
[0030] Figure 2 This is a flowchart illustrating the service request processing method shown in the second embodiment of this disclosure. It should be noted that this embodiment is applied to a microservice gateway.
[0031] like Figure 2 As shown, the service request processing method includes the following steps: Step 201: Retrieve service configuration information associated with the service cluster from the database.
[0032] Step 202: In response to receiving a service request from the client, sequentially traverse the configuration sub-information associated with multiple processing nodes.
[0033] It should be noted that the service configuration information includes: configuration sub-information associated with multiple processing nodes in the request processing chain. These multiple processing nodes include: authentication processing node, rate limiting processing node, circuit breaker processing node, and log processing node.
[0034] To decouple service requests from processing nodes and improve system flexibility, as an example, the configuration sub-information associated with multiple processing nodes is traversed sequentially to determine whether to process the service request using the filter indicated by the corresponding processing node.
[0035] Step 203: Obtain the on / off state of the filter indicated by the currently traversed processing node.
[0036] To avoid unnecessary processing operations and improve efficiency, as an example, the on / off state of the filter indicated by the currently traversed processing node is determined based on its configuration sub-information. For instance, if the currently traversed processing node is an authentication processing node, its on / off state is determined by checking whether the value of the configuration parameter `filterAuthorizeName` corresponding to the authentication processing node, obtained from the service configuration information, is empty.
[0037] Step 204: In response to the filter being on as indicated by the currently traversed processing node, obtain the parameter conditions of at least one configuration parameter configured by the currently traversed processing node from the configuration sub-information associated with the currently traversed processing node.
[0038] To accurately determine whether to use the filter indicated by the corresponding processing node to process the service request, as a possible implementation, if the filter indicated by the currently traversed processing node is in the on state, the actual parameter value of the at least one configuration parameter in the service request is determined based on the parameter conditions of at least one configuration parameter configured by the currently traversed processing node.
[0039] As an example, from the configuration sub-information associated with the currently traversed processing node, retrieve and obtain the rules or thresholds (i.e., parameter conditions) of one or more configuration parameters configured by that node, in order to understand the rules or standards that the processing node should follow when processing requests.
[0040] For example, taking the currently traversed processing node as the rate limiting processing node, the configuration parameter corresponding to the rate limiting processing node can be: refreshRate per second, where the parameter condition for refreshRate is that the upper limit of refreshRate per second is 1000.
[0041] Step 205: Parse the service request to obtain the actual parameter value of at least one service parameter.
[0042] Continuing with the current processing node as the rate limiting processing node, and the configuration parameter corresponding to the rate limiting processing node being traffic per second, we determine the actual value of traffic per second by parsing the service requests.
[0043] Step 206: If the actual parameter values of each service parameter meet the corresponding parameter conditions, generate the calculation result to indicate the filter indicated by the currently traversed processing node to process the service request.
[0044] For example, taking the currently traversed processing node as the rate limiting processing node, when the actual value of the traffic per second reaches the upper limit of the traffic per second, the calculation result is generated to process the service request using the rate limiting filter indicated by the rate limiting processing node.
[0045] Furthermore, it should be noted that if at least one configuration parameter does not meet the corresponding parameter condition, or if the filter indicated by the currently traversed processing node is in a closed state, the process continues to traverse the next processing node until the target processing node is reached. In this case, a calculation result is generated to indicate that the service request is processed using the filter indicated by the target processing node. When the last processing node is traversed, the traversal stops. In this case, the filter indicated by the target processing node is in a closed state and the actual parameter values of each configuration parameter configured by the target processing node meet the corresponding parameter conditions.
[0046] Step 207: Based on the calculation results, process the service request using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0047] It should be noted that the execution processes of steps 201 and 207 can be implemented in any of the various embodiments of this disclosure. This disclosure does not limit these processes and will not elaborate further.
[0048] In summary, by sequentially traversing the configuration sub-information associated with multiple processing nodes, the processing logic can be dynamically adjusted according to actual needs. When the filter switch status indicated by the currently traversed processing node is on, the parameter conditions of the configuration parameters of that node are further obtained, and the service request is parsed to verify whether the actual value of the configuration parameter meets the corresponding parameter conditions. If all relevant parameters meet the corresponding parameter conditions, the filter indicated by the current processing node is selected to process the service request. This not only improves the flexibility and scalability of the system, but also ensures that service requests are processed accurately and effectively according to predetermined rules and conditions, thus improving the user experience.
[0049] To clearly illustrate how the above embodiments process service requests based on calculation results using filters in the microservice gateway indicated by at least one processing node in the request processing chain, this disclosure proposes another service request processing method.
[0050] Figure 3 This is a flowchart illustrating the service request processing method according to the third embodiment of this disclosure. It should be noted that this embodiment is applied to a microservice gateway.
[0051] like Figure 3As shown, the service request processing method includes the following steps: Step 301: Retrieve service configuration information associated with the service cluster from the database.
[0052] Step 302: In response to receiving a service request from the client, the specified service middleware in the microservice gateway is used to calculate the service request based on the service configuration information to obtain the calculation result.
[0053] Step 303: Based on the filter indicated by the calculation result, obtain at least one processing parameter corresponding to the indicated filter from the service configuration information.
[0054] In this embodiment of the disclosure, the processing parameters corresponding to the filters indicated by different processing nodes are different. For example, such as Figure 4 As shown, when the processing node is an authentication processing node, the processing parameters corresponding to the authentication filter indicated by the authentication processing node include: header, host, request method, requester's Internet Protocol (IP) address, Uniform Resource Locator (URL) address, request parameters, cookie, and time. When the processing node is a rate limiting processing node, the processing parameters corresponding to the rate limiting filter indicated by the rate limiting processing node include: requester's IP, resource URL, and user information. When the processing node is a circuit breaker processing node, the processing parameters indicated by the circuit breaker processing node include the circuit breaker threshold. When the processing node is a log processing node, the processing parameters corresponding to the log filter indicated by the log processing node include: request method, requester's IP, resource URL address, etc. The processing parameters corresponding to the log filter are used to filter and process logs.
[0055] Step 304: Parse the service request using the indicated filter to obtain the parameter value of at least one processing parameter.
[0056] In order to process service requests accurately, as an example, the service request is parsed using the indicated filter to extract and obtain the parameter value of at least one processing parameter from the service request.
[0057] Step 305: Using the indicated filter, process the service request according to the parameter value of at least one processing parameter.
[0058] In order to accurately process service requests, as one possible implementation, a filter indicated by the calculation results is used to record, compare, or verify the parameter values of at least one processing parameter according to preset rules and conditions.
[0059] As an example, in response to the indicated filter being an authentication filter, the authentication processing logic information associated with the service cluster is obtained from the service configuration information; using the authentication filter, the parameter value of at least one processing parameter is authenticated according to the authentication processing logic information.
[0060] In other words, when the indicated filter is an authentication filter, the authentication processing logic information associated with the service cluster is obtained from the service configuration information; then, the authentication filter performs authentication processing on the parameter values of at least one processing parameter according to the authentication processing logic information to ensure that these parameter values meet specific security requirements and permission settings.
[0061] As another example, in response to the indicated filter being a rate limiting filter, the rate limiting rules associated with the service cluster are obtained from the service configuration information; the rate limiting filter is then used to rate limit the parameter value of at least one processing parameter according to the rate limiting rules.
[0062] In other words, when the indicated filter is a rate limiting filter, the rate limiting rules associated with the service cluster are obtained from the service configuration information. Subsequently, the rate limiting filter performs rate limiting on the parameter value of at least one processing parameter according to the rate limiting rules to ensure the stability and availability of the service. This achieves the goal of preventing the service from crashing due to overload by controlling the service request rate or concurrency.
[0063] As another example, in response to the indicated filter being a circuit breaker filter, the circuit breaker threshold of at least one processing parameter is obtained from the service configuration information; in response to any processing parameter having a value greater than or equal to the corresponding circuit breaker threshold, the service request is circuit breaker processed.
[0064] It's important to understand that as the number of service nodes in a service cluster increases and their interdependencies become more complex, an anomaly in one service node can paralyze the entire service cluster—a phenomenon known as the "avalanche effect." To avoid this problem, the circuit breaker filter obtains the circuit breaker threshold for at least one processing parameter from the service configuration information. When the value of any processing parameter is greater than or equal to the corresponding circuit breaker threshold, the circuit breaker filter performs circuit breaking processing on the service request to prevent the service cluster from crashing.
[0065] As another example, a log filter is used in response to a processing node in the computation result to record at least one processing parameter.
[0066] It's important to understand that log filters are used to capture key information during the processing of service requests, including but not limited to the values of processing parameters. By recording these parameters, the status of service nodes can be traced back during subsequent analysis, monitoring, or debugging, facilitating troubleshooting, performance optimization, and service improvement.
[0067] Therefore, when the filter indicated by the processing node in the calculation result is a log filter, at least one processing parameter is recorded.
[0068] It should be noted that the execution process of steps 301 to 302 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.
[0069] In summary, by using the filter indicated by the calculation results, at least one processing parameter corresponding to the indicated filter is obtained from the service configuration information; the service request is parsed using the indicated filter to obtain the parameter value of at least one processing parameter; and the service request is processed using the indicated filter based on the parameter value of at least one processing parameter. Thus, the filter is automatically matched according to the calculation results, and the corresponding processing parameters are automatically extracted from the service configuration information. This achieves the processing of the corresponding processing parameters according to the processing logic corresponding to the filter, improving the flexibility and accuracy of service request processing.
[0070] To clearly illustrate how the service configuration information associated with the service cluster is obtained from the database in the above embodiments, this disclosure proposes another service request processing method.
[0071] Figure 5 This is a flowchart illustrating the service request processing method shown in the fourth embodiment of this disclosure. It should be noted that this embodiment is applied to a microservice gateway.
[0072] like Figure 5 As shown, the service request processing method includes the following steps: Step 501: Retrieve multiple service configuration tables associated with the service cluster from the database.
[0073] As an example, when the microservice gateway starts, it sends a configuration information retrieval request to retrieve multiple service configuration tables associated with the service cluster from the database, thereby obtaining service configuration information from multiple service configuration tables.
[0074] In this implementation, as shown in Figures 6(A) and 6(B), multiple service configuration tables include: a path configuration table, a load information table, a load rule table, a service interface registry, a rate limiting and circuit breaking rule table, and a script configuration table. There are mapping relationships between these multiple service configuration tables. For example, the mapping relationship between the path configuration table and the service interface registry is one-to-one, meaning that each service interface has a unique corresponding path configuration information in the registry. The mapping relationship between the service interface registry and the load rule table is one-to-one or one-to-zero, meaning that each service interface has a unique corresponding load rule in the registry, or there is no corresponding load rule.
[0075] It should be noted that the path configuration table stores the processing routing information associated with service requests, the load information table stores the basic load information associated with the service cluster, the load rule table stores the load rule information to maintain the load balance of the service cluster, the service interface registry stores the basic service interface information of the service cluster, the rate limiting and circuit breaking rule table stores the rule information for rate limiting and circuit breaking of service requests, and the script configuration table stores the configuration information of filters in the microservice gateway (such as authentication logic information).
[0076] In addition, it should be noted that before retrieving multiple service configuration tables associated with the server from the database, the service configuration information must be configured in the database. The service configuration information is configured in the database using the following steps: 1. In response to the creation operation, create multiple blank service configuration tables in the database and establish the mapping relationship between the multiple blank service configuration tables; 2. In response to configuration operations on service configuration information, configure service configuration information in multiple blank service configuration tables.
[0077] Step 502: Obtain service configuration information from multiple service configuration tables.
[0078] Furthermore, service configuration information is extracted from multiple service configuration tables.
[0079] Step 503: Store the service configuration information in the memory of the microservice gateway.
[0080] To improve the access speed of service configuration information and reduce performance bottlenecks caused by frequent database access, as an example, the service configuration information will be directly loaded and stored in the memory space of the microservice gateway.
[0081] Step 504: In response to receiving a service request from the client, the specified service middleware in the microservice gateway is used to calculate the service request based on the service configuration information to obtain the calculation result.
[0082] Step 505: Based on the calculation results, process the service request using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0083] It should be noted that the execution process of steps 504 to 505 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.
[0084] In summary, by retrieving multiple service configuration tables associated with the service cluster from the database and extracting service configuration information from them, and then storing this information in the memory of the microservice gateway, we not only improve the access speed of service configuration information and reduce performance bottlenecks caused by frequent database access, but also enable microservices to quickly and efficiently obtain the latest configuration information when needed. Furthermore, by centrally storing configuration information in the memory of the microservice gateway, we simplify the management and maintenance process of configuration information, and improve the flexibility and scalability of the microservice architecture.
[0085] Based on any of the above embodiments, the service request is processed according to the filter indicated by at least one processing node. When the processing result meets the set conditions, the service request is load-forwarded. The following describes the process in conjunction with... Figure 7 The embodiments are described in detail.
[0086] Figure 7 This is a flowchart illustrating the service request processing method according to the fifth embodiment of this disclosure. It should be noted that this embodiment is applied to a microservice gateway.
[0087] like Figure 7 As shown, the service request processing method includes the following steps: Step 701: Obtain the processing result of the service request processed by the filter indicated by at least one processing node.
[0088] In this embodiment of the disclosure, a filter indicated by at least one processing node is used to process the service request to obtain a processing result, which includes whether the service request passes authentication, whether it is rate-limited, and / or whether it is circuit-broken.
[0089] Step 702: In response to the processing result meeting the set conditions, obtain the load balancing strategy of the service cluster from the service configuration information.
[0090] The load balancing strategy includes load weights, which are used to determine the upper limit of the load on each service node in the service cluster.
[0091] As an example, the processing result indicates that the service request has passed authentication, has not been rate-limited, and / or has not been circuit-breaking. The load balancing strategy for the service cluster is obtained from the service configuration information. This load balancing strategy includes, but is not limited to, Round Robin, Random, and Least Connections. Round Robin involves sequentially assigning requests to each service node in the service node list until the end of the list, then looping. Random selection randomly selects a service node from the service cluster to respond to the request. Least Connections selection chooses the service node with the fewest current connections (or requests) to respond to new requests.
[0092] Step 703: Based on the load weight, execute a load balancing strategy for the service request to determine the target service node from the service cluster to respond to the service request.
[0093] As an example, based on the load balancing strategy, the probability of each service node being selected is calculated according to the load weight of the service node and the current load status. Then, based on the probability of each service node being selected, a target service node is selected from multiple service nodes to respond to the service request.
[0094] Step 704: The service request is scheduled to the target service node so that the target service node can respond to the service request.
[0095] Subsequently, after receiving the service request, the target service node processes the service request and generates a corresponding response. Then, the target service node returns the response result to the microservice gateway, and the microservice gateway returns the response result to the client.
[0096] In summary, by obtaining the processing results of service requests processed by filters indicated by at least one processing node; in response to the processing results meeting set conditions, the load balancing strategy of the service cluster is obtained from the service configuration information; based on load weights, the load balancing strategy is executed on the service requests to determine the target service node from the service cluster to respond to the service requests; and the service requests are scheduled to the target service node so that the target service node can respond to the service requests. This not only improves the resource utilization of the service cluster but also enhances the scalability and flexibility of the service. The load balancing strategy based on load weights ensures that service requests are evenly distributed across the nodes in the service cluster, avoiding single-point overload. This allows the distributed system built on a microservice architecture to better handle various service requests, improving overall service quality and user experience.
[0097] To illustrate the above embodiments more clearly, examples are given below.
[0098] For example, such as Figure 8 As shown, taking the microservice gateway as the gateway between the front-end service nginx and the application server (instead of letting the front-end service directly request the application server) as an example, the gateway uniformly completes operations such as rate limiting, authentication, and circuit breaking, and finally load-loads qualified requests to the back-end application server.
[0099] This solution integrates the Sentinel service (a designated service middleware) into the microservice gateway. The Sentinel service provides authentication, rate limiting, and circuit breaker algorithms. Rate limiting and circuit breaker configuration information is persisted to a database. This configuration information is read when the microservice gateway starts. When a service request arrives, the configuration information is sent to the Sentinel service for calculation. Based on the calculation result, it determines whether to load balance to the application service. Furthermore, it should be noted that the load balancing logic in this solution is achieved by integrating Hystrix into the microservice gateway, reading application server registration information from Nacos, and performing load forwarding based on load weights.
[0100] Corresponding to the service request processing method provided in the above embodiments, this disclosure also provides a service request processing apparatus. Since the service request processing apparatus provided in this disclosure corresponds to the service request processing method provided in the above embodiments, the implementation of the service request processing method is also applicable to the service request processing apparatus provided in this disclosure, and will not be described in detail in this disclosure.
[0101] Figure 9 This is a schematic diagram of the service request processing apparatus shown in the sixth embodiment of this disclosure.
[0102] like Figure 9 As shown, the service request processing device 900 includes: an acquisition module 910, a calculation module 920, and a processing module 930.
[0103] The acquisition module 910 is used to retrieve service configuration information associated with the service cluster from the database; the calculation module 920 is used to respond to the service request sent by the client, and use the specified service middleware in the microservice gateway to calculate the service request according to the service configuration information to obtain the calculation result; the processing module 930 is used to process the service request according to the calculation result, using the filter in the microservice gateway indicated by at least one processing node in the request processing chain.
[0104] As one possible implementation of this disclosure, the service configuration information includes: configuration sub-information associated with multiple processing nodes in the request processing chain; a calculation module 920, configured to, in response to receiving a service request sent by a client, sequentially traverse the configuration sub-information associated with multiple processing nodes; obtain the on / off state of the filter indicated by the currently traversed processing node; in response to the filter indicated by the currently traversed processing node being in an on / off state, obtain parameter conditions for at least one configuration parameter configured by the currently traversed processing node from the configuration sub-information associated with the currently traversed processing node; parse the service request to obtain the actual parameter value of at least one configuration parameter; and, if the actual parameter values of each service parameter satisfy the corresponding parameter conditions, generate a calculation result indicating that the service request should be processed using the filter indicated by the currently traversed processing node.
[0105] In one possible implementation of this disclosure, the calculation module 920 is further configured to, in response to the presence of a target parameter in at least one configuration parameter, or the filter indicated by the currently traversed processing node being in a closed state, continue traversing the next processing node until the target processing node is reached, generate a calculation result indicating that the service request is processed using the filter indicated by the target processing node; wherein the actual parameter value of the target parameter does not satisfy the corresponding parameter condition, the filter indicated by the target processing node is in a closed state, and the actual parameter values of each configuration parameter configured by the target processing node satisfy the corresponding parameter condition.
[0106] As one possible implementation of this disclosure, the processing module 930 is configured to obtain at least one processing parameter corresponding to the indicated filter from the service configuration information according to the filter indicated by the calculation result; parse the service request using the indicated filter to obtain the parameter value of at least one processing parameter; and process the service request using the indicated filter according to the parameter value of at least one processing parameter.
[0107] As one possible implementation of this disclosure, the processing module 930 is configured to, in response to the indicated filter being an authentication filter, obtain authentication processing logic information associated with the service cluster from the service configuration information; use the authentication filter to perform authentication processing on the parameter values of at least one processing parameter according to the authentication processing logic information; and, in response to the indicated filter being a rate limiting filter, obtain rate limiting rules associated with the service cluster from the service configuration information; use the rate limiting filter to perform rate limiting processing on the parameter values of at least one processing parameter according to the rate limiting rules.
[0108] As one possible implementation of this disclosure, the processing module 930 is configured to, in response to the indicated filter being a circuit breaker filter, obtain the circuit breaker threshold of at least one processing parameter from the service configuration information; in response to the parameter value of any of the at least one processing parameter being greater than or equal to the corresponding circuit breaker threshold, perform circuit breaker processing on the service request; and in response to the filter indicated by the processing node in the calculation result being a log filter, record at least one processing parameter.
[0109] As one possible implementation of this disclosure, the acquisition module 910 is used to acquire multiple service configuration tables associated with the service cluster from the database; acquire the service configuration information from the multiple service configuration tables; and store the service configuration information in the memory of the microservice gateway.
[0110] As one possible implementation of this disclosure, service configuration information is configured into the database using the following steps: in response to a creation operation, multiple blank service configuration tables are created in the database, and a mapping relationship is established between the multiple blank service configuration tables; in response to a configuration operation on service configuration information, the service configuration information is configured in the multiple blank service configuration tables.
[0111] As one possible implementation of this disclosure, the service request processing device 900 further includes a scheduling module.
[0112] The scheduling module is configured to: obtain the processing result of the filter indicated by at least one processing node processing the service request; in response to the processing result meeting the set conditions, obtain the load balancing strategy of the service cluster from the service configuration information; wherein the load balancing strategy includes load weights, which are used to determine the upper limit of the load of each service node in the service cluster; based on the load weights, execute the load balancing strategy on the service request to determine the target service node for responding to the service request from the service cluster; and schedule the service request to the target service node so that the target service node can respond to the service request.
[0113] The service request processing apparatus of this disclosure pre-configures service configuration information associated with the service cluster in the database. The microservice gateway dynamically obtains the service configuration information associated with the service cluster from the database, avoiding the problem of non-persistent service configuration information. When a service request is received from a client, the microservice gateway uses a specified service middleware to calculate the request based on the service configuration information, obtains the calculation result, and processes the request through a filter in the request processing chain based on the calculation result. This realizes intelligent routing, load balancing, dynamic rate limiting, or circuit breaking filtering of service requests, improves the scalability, flexibility, and security of the system, and reduces the coupling of the system, making the management and maintenance of the service cluster more efficient.
[0114] In an exemplary embodiment, an electronic device is also proposed.
[0115] The electronic devices include: processor; Memory used to store processor-executable instructions; The processor is configured to execute instructions to implement the service request processing method as proposed in any of the foregoing embodiments.
[0116] As an example, Figure 10 This is a schematic diagram of the structure of an electronic device 1000 as shown in an exemplary embodiment of this disclosure, as follows: Figure 10 As shown, the aforementioned electronic device 1000 may further include: The memory 1010 and the processor 1020 are connected by a bus 1030, which connects different components (including the memory 1010 and the processor 1020). The memory 1010 stores a computer program, which implements the service request processing method described in this embodiment when the processor 1020 executes the program.
[0117] Bus 1030 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0118] Electronic device 1000 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by electronic device 1000, including volatile and non-volatile media, removable and non-removable media.
[0119] Memory 1010 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 1040 and / or cache memory 1050. Memory 1010 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 1060 can be used to read and write non-removable, non-volatile magnetic media (… Figure 10 Not shown; usually referred to as a "hard drive"). Although Figure 10 As not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 1030 via one or more data media interfaces. Memory 1010 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.
[0120] A program / utility 1080 having a set (at least one) of program modules 1070 may be stored in, for example, memory 1010. Such program modules 1070 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 1070 typically perform the functions and / or methods described in the embodiments of this disclosure.
[0121] Electronic device 1000 can also communicate with one or more external devices 1090 (e.g., keyboard, pointing device, display 1091, etc.), one or more devices that enable a user to interact with electronic device 1000, and / or any device that enables electronic device 1000 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 1092. Furthermore, electronic device 1000 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 1093. As shown, network adapter 1093 communicates with other modules of electronic device 1000 via bus 1030. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0122] The processor 1020 performs various functional applications and data processing by running programs stored in the memory 1010.
[0123] It should be noted that the implementation process and technical principles of the electronic device in this embodiment are explained in the foregoing description of the service request processing method of this disclosure embodiment, and will not be repeated here.
[0124] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions that can be executed by a processor of an electronic device to perform the service request processing method proposed in any of the above embodiments. Optionally, the computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0125] In an exemplary embodiment, a computer program product is also provided, including a computer program / instructions, characterized in that the computer program / instructions, when executed by a processor, implement the service request processing method proposed in any of the above embodiments.
[0126] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0127] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A service request processing method, characterized in that, Applied to a microservice gateway, the method includes: The system retrieves multiple service configuration tables associated with the service cluster from the database; retrieves service configuration information from the multiple service configuration tables; and stores the service configuration information in the memory of the microservice gateway. Before retrieving the multiple service configuration tables associated with the service cluster from the database, the service configuration information is configured in the database using the following steps: in response to a creation operation, multiple blank service configuration tables are created in the database, and a mapping relationship is established between the multiple blank service configuration tables; in response to a configuration operation on the service configuration information, the service configuration information is configured in the multiple blank service configuration tables. In response to receiving a service request from a client, the specified service middleware in the microservice gateway is used to calculate the service request based on the service configuration information to obtain the calculation result; Based on the calculation results, the service request is processed using a filter in the microservice gateway indicated by at least one processing node in the request processing chain.
2. The method according to claim 1, characterized in that, The service configuration information includes: configuration sub-information associated with multiple processing nodes in the request processing chain; In response to receiving a service request from a client, the specified service middleware in the microservice gateway performs calculations on the service request based on the service configuration information to obtain a calculation result, including: In response to receiving a service request from a client, the configuration sub-information associated with the multiple processing nodes is traversed sequentially. Get the on / off state of the filter indicated by the currently traversed processing node; In response to the filter being enabled as indicated by the currently traversed processing node, the parameter conditions of at least one configuration parameter configured by the currently traversed processing node are obtained from the configuration sub-information associated with the currently traversed processing node. The service request is parsed to obtain the actual parameter value of the at least one configuration parameter; If the actual parameter values of each service parameter meet the corresponding parameter conditions, a calculation result is generated to indicate the filter indicated by the currently traversed processing node to process the service request.
3. The method according to claim 2, characterized in that, The method further includes: In response to the presence of a target parameter in at least one of the configuration parameters, or if the filter indicated by the currently traversed processing node is in a closed state, the process continues to traverse the next processing node until the target processing node is reached, and generates a calculation result to indicate that the service request is processed using the filter indicated by the target processing node. Wherein, the actual parameter value of the target parameter does not meet the corresponding parameter condition, the switch state of the filter indicated by the target processing node is on, and the actual parameter values of each configuration parameter configured by the target processing node all meet the corresponding parameter conditions.
4. The method according to any one of claims 1-3, characterized in that, The step of processing the service request using a filter in the microservice gateway indicated by at least one processing node in the request processing chain, based on the calculation result, includes: Based on the filter indicated by the calculation result, at least one processing parameter corresponding to the indicated filter is obtained from the service configuration information; The service request is parsed using the indicated filter to obtain the parameter value of the at least one processing parameter; The service request is processed using the indicated filter, based on the parameter value of the at least one processing parameter.
5. The method according to claim 4, characterized in that, The step of processing the service request using the indicated filter according to the parameter value of the at least one processing parameter includes: In response to the indicated filter being an authentication filter, the authentication processing logic information associated with the service cluster is obtained from the service configuration information; Using the authentication filter, the parameter values of the at least one processing parameter are authenticated according to the authentication processing logic information; In response to the indicated filter being a rate limiting filter, the rate limiting rules associated with the service cluster are obtained from the service configuration information; The flow-limiting filter is used to limit the parameter value of at least one processing parameter according to the flow-limiting rules.
6. The method according to claim 4, characterized in that, The step of processing the service request using the indicated filter according to the parameter value of the at least one processing parameter includes: In response to the indicated filter being a circuit breaker filter, the circuit breaker threshold of the at least one processing parameter is obtained from the service configuration information; In response to the fact that the value of any of the at least one processing parameters is greater than or equal to the corresponding circuit breaker threshold, the service request is subjected to circuit breaker processing; The filter indicated by the processing node in the calculation result is a log filter, which records the at least one processing parameter.
7. The method according to claim 1, characterized in that, The method further includes: Obtain the processing result of the filter indicated by the at least one processing node processing the service request; In response to the processing result satisfying the set conditions, the load balancing strategy of the service cluster is obtained from the service configuration information; wherein, the load balancing strategy includes load weights, which are used to determine the upper limit of the load of each service node in the service cluster. Based on the load weight, the load balancing strategy is executed on the service request to determine the target service node from the service cluster for responding to the service request; The service request is scheduled to the target service node so that the target service node can respond to the service request.
8. A service request processing apparatus, characterized in that, The device, applied to a microservice gateway, includes: The acquisition module is used to acquire multiple service configuration tables associated with the service cluster from the database; acquire service configuration information from the multiple service configuration tables; and store the service configuration information in the memory of the microservice gateway. Before acquiring the multiple service configuration tables associated with the service cluster from the database, the service configuration information is configured in the database using the following steps: in response to a creation operation, multiple blank service configuration tables are created in the database, and a mapping relationship is established between the multiple blank service configuration tables; in response to a configuration operation on the service configuration information, the service configuration information is configured in the multiple blank service configuration tables. The calculation module is used to respond to a service request sent by a client, and to use a specified service middleware in the microservice gateway to calculate the service request according to the service configuration information to obtain the calculation result. The processing module is configured to process the service request using a filter in the microservice gateway indicated by at least one processing node in the request processing chain, based on the calculation result.