Microservice Instance Routing Method, API Gateway, and Computing Service Device
By extracting and analyzing multi-dimensional information of inbound requests in the API gateway and selecting the most suitable microservice instance for routing, the problem of inflexible and accurate routing decisions in the existing technology is solved, and system performance and user experience are improved.
Patent Information
- Application Number
- CN202510473465.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-16
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-04-16
AI Technical Summary
The routing decisions of existing API gateways are not flexible and accurate enough to effectively manage and route microservice instances, resulting in a decline in system performance and user experience.
By extracting the target microservice instance matching information of the inbound request in the API gateway, including content type, received content type, client type and network connection type, performing multi-dimensional matching and analysis, thereby selecting the most suitable microservice instance for routing.
It improves the flexibility and accuracy of API gateway routing decisions, improves system performance, reliability and user experience, optimizes traffic allocation and resource utilization, and ensures that different types of clients have the best service experience under various network conditions.
Smart Images

Figure CN120017720B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of API gateways, and in particular to a microservice instance routing method, an API gateway, and a computing service device. Background Art
[0002] With the development of Internet technology, the microservice architecture has become one of the important models for building large-scale distributed systems. By decomposing an application into a series of independent small services (i.e., microservices), it achieves higher modularity, maintainability, and scalability. However, with the growth of the number of services and the diversification of user needs, how to effectively manage and route these microservices has become a new challenge. As a key component in the microservice architecture, the API (Application Programming Interface) gateway is responsible for receiving external requests and forwarding them to the correct microservice instance, and its routing strategy directly affects the performance of the entire system and the user experience.
[0003] Currently, most API gateways adopt a load balancing method to select an instance from multiple microservice instances under the same microservice to process requests. Common load balancing algorithms include round-robin, least connections, weighted round-robin, etc. Although these methods can ensure the uniform distribution of traffic to a certain extent, they ignore the specific characteristics and technical conditions of the client inbound requests, resulting in inflexible and inaccurate routing decisions. Summary of the Invention
[0004] The main purpose of this application is to provide a microservice instance routing method, an API gateway, and a computing service device, aiming to solve the technical problem that the routing decision of the API gateway in the related technology is not flexible and accurate enough.
[0005] To achieve the above object, this application provides a microservice instance routing method, which is applied to an API gateway and includes:
[0006] After receiving an inbound request sent by a client, extract target microservice instance matching information from the inbound request, and determine the target microservice corresponding to the inbound request, where the target microservice instance matching information includes at least one of the content type, received content type, client type, and network connection type corresponding to the inbound request;
[0007] Based on the target microservice instance matching information, match the target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice;
[0008] Obtain the network address corresponding to the target microservice instance, and route the inbound request to the target microservice instance based on the network address.
[0009] In one embodiment, the step of matching the target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice based on the target microservice instance matching information includes:
[0010] Obtain the microservice instance matching conditions previously set for each microservice instance under the target microservice respectively, and compare the target microservice instance matching information with the microservice instance matching conditions corresponding to each microservice instance to obtain the comparison results corresponding to each microservice instance;
[0011] Determine the target microservice instance corresponding to the inbound request from each microservice instance according to the comparison results corresponding to each microservice instance.
[0012] In one embodiment, the step of determining the target microservice instance corresponding to the inbound request from each microservice instance according to the comparison results corresponding to each microservice instance includes:
[0013] According to the comparison results corresponding to each microservice instance, use the microservice instances whose microservice instance matching conditions are satisfied by the target microservice instance matching information among each microservice instance as alternative microservice instances;
[0014] When the number of alternative microservice instances is one, determine the alternative microservice instance as the target microservice instance corresponding to the inbound request.
[0015] In one embodiment, after the step of using the microservice instances whose microservice instance matching conditions are satisfied by the target microservice instance matching information among each microservice instance as alternative microservice instances according to the comparison results corresponding to each microservice instance, it further includes:
[0016] When the number of alternative microservice instances is greater than one, determine the target microservice instance corresponding to the inbound request from each alternative microservice instance based on a preset microservice instance selection strategy.
[0017] In one embodiment, the preset microservice instance selection strategy is: preferentially select the alternative microservice instance with a smaller number of connections;
[0018] The step of determining the target microservice instance corresponding to the inbound request from each alternative microservice instance based on the preset microservice instance selection strategy includes:
[0019] Obtain the number of connections and the connection number threshold of each alternative microservice instance, and use the alternative microservice instances with the number of connections less than the connection number threshold among each alternative microservice instance as candidate microservice instances;
[0020] From the candidate microservice instances, determine the microservice instance with the minimum number of connections as the target microservice instance corresponding to the inbound request.
[0021] In one embodiment, the preset microservice instance selection policy is: preferentially select candidate microservice instances with higher priorities.
[0022] The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on the preset microservice instance selection policy includes:
[0023] Obtain the priorities of each candidate microservice instance, and use the candidate microservice instance with the highest priority among each candidate microservice instance as the candidate microservice instance.
[0024] Randomly select a microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
[0025] In one embodiment, the preset microservice instance selection policy is: preferentially select candidate microservice instances with lower CPU loads.
[0026] The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on the preset microservice instance selection policy includes:
[0027] Obtain the CPU loads of each candidate microservice instance, and use the candidate microservice instance with the lowest CPU load among each candidate microservice instance as the candidate microservice instance.
[0028] Randomly select a microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
[0029] In one embodiment, the target microservice instance matching information further includes at least one of the IP address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the inbound request.
[0030] In addition, to achieve the above object, the present application further provides an API gateway, and the API gateway includes:
[0031] A receiving module, configured to, after receiving an inbound request sent by a client, extract target microservice instance matching information from the inbound request, and determine the target microservice corresponding to the inbound request, where the target microservice instance matching information includes at least one of the content type, received content type, client type, and network connection type corresponding to the inbound request.
[0032] A matching module, configured to match, based on the target microservice instance matching information, a target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice;
[0033] A routing module, configured to obtain a network address corresponding to the target microservice instance, and route the inbound request to the target microservice instance based on the network address.
[0034] In addition, to achieve the above object, the present application further provides a computing service device, where the computing service device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the microservice instance routing method as described above are implemented.
[0035] The present application provides a microservice instance routing method, an API gateway, and a computing service device, relating to the technical field of API gateways. The method is applied to an API gateway and includes: after receiving an inbound request sent by a client, extracting target microservice instance matching information from the inbound request, and determining a target microservice corresponding to the inbound request, where the target microservice instance matching information includes at least one of a content type corresponding to the inbound request, a receiving content type, a client type, and a network connection type; based on the target microservice instance matching information, matching a target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice; obtaining a network address corresponding to the target microservice instance, and routing the inbound request to the target microservice instance based on the network address.
[0036] Compared with the traditional routing method based on a load balancing algorithm, the present application comprehensively considers multiple factors (such as content type, receiving content type, client type, and network connection type) as the basis for microservice instance routing decisions, performs fine-grained analysis and matching on the inbound request through multi-dimensional matching information, thereby improving the flexibility and accuracy of the API gateway routing decision, achieving accurate microservice instance routing, enabling the API gateway to not only more intelligently select the specific microservice instance most suitable for processing the request, but also significantly improve the system performance, reliability, and user experience, and further dynamically adapt to different application scenarios, provide more personalized and optimized services, optimize traffic distribution, improve resource utilization rate and service response speed, and ensure that different types of clients can obtain the best service experience under various network conditions. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0038] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on the structures shown in these drawings.
[0039] Figure 1 It is a schematic flowchart of the microservice instance routing method in the embodiment of the present application;
[0040] Figure 2 It is a schematic flowchart of the matching process of the target microservice instance in the embodiment of the present application;
[0041] Figure 3 It is a schematic flowchart of the specific matching process of the target microservice instance in the embodiment of the present application;
[0042] Figure 4 It is a schematic diagram of the module structure of the API gateway in the embodiment of the present application;
[0043] Figure 5 It is a schematic diagram of the device structure of the hardware operating environment involved in the microservice instance routing method in the embodiment of the present application.
[0044] The implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the drawings. Detailed Embodiments
[0045] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0046] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0047] Currently, most API gateways adopt the method of load balancing to select an instance from multiple microservice instances under the same microservice to process requests. Common load balancing algorithms include round robin, least connections, weighted round robin, etc. Although these methods can ensure the uniform distribution of traffic to a certain extent, they ignore the specific characteristics and technical conditions of the client inbound requests, lack fine-grained analysis and multi-dimensional matching of the inbound requests, resulting in inflexible and inaccurate routing decisions.
[0048] For example, traditional routing strategies are difficult to make targeted optimizations for the different requirements of mobile applications and web clients, as well as the differences between WiFi (Wireless Fidelity) and mobile data networks. In addition, when faced with complex business logics and diverse request formats, existing routing mechanisms appear too rigid to flexibly handle rapidly changing application scenarios.
[0049] The main solution of this application is a microservice instance routing method, which is applied to an API gateway and includes: after receiving an inbound request sent by a client, extracting target microservice instance matching information from the inbound request and determining the target microservice corresponding to the inbound request, where the target microservice instance matching information includes at least one of the content type, received content type, client type, and network connection type corresponding to the inbound request; based on the target microservice instance matching information, matching the target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice; obtaining the network address corresponding to the target microservice instance, and routing the inbound request to the target microservice instance based on the network address.
[0050] Compared with traditional routing methods based on load balancing algorithms, this application comprehensively considers multiple factors (such as content type, received content type, client type, and network connection type) as the basis for microservice instance routing decisions, and conducts fine-grained analysis and matching of inbound requests through multi-dimensional matching information, thereby improving the flexibility and accuracy of API gateway routing decisions, achieving precise microservice instance routing, enabling the API gateway to not only more intelligently select the specific microservice instance most suitable for processing requests, but also significantly enhance the system's performance, reliability, and user experience, and then dynamically adapt to different application scenarios, provide more personalized and optimized services, optimize traffic distribution, improve resource utilization and service response speed, and ensure that different types of clients can obtain the best service experience under various network conditions.
[0051] To better understand the technical solution of this application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific implementation manners.
[0052] Please refer to Figure 1 , Figure 1 , which is a schematic flowchart of the microservice instance routing method in an embodiment of this application.
[0053] In this embodiment, the microservice instance routing method is applied to an API gateway, and this method includes steps S100 to S300:
[0054] Step S100, after receiving the inbound request sent by the client, extract the target microservice instance matching information from the candidate microservice instance inbound request, and determine the target microservice corresponding to the candidate microservice instance inbound request, wherein the candidate microservice instance target microservice instance matching information includes at least one of the content type corresponding to the candidate microservice instance inbound request, the received content type, the client type, and the network connection type;
[0055] Those skilled in the art will know that an inbound request refers to an HTTP (Hyper Text Transfer Protocol) / HTTPS (Hyper Text Transfer Protocol Secure) request from a client (such as a mobile application, a web browser, etc.), and a microservice instance refers to a running instance of a microservice.
[0056] In this embodiment, the target microservice refers to the microservice used to respond to and process the inbound request, that is, the microservice that needs to be called to process the inbound request. The target microservice instance matching information is information extracted from the inbound request, which is used to match the specific microservice instance that is most suitable for processing the inbound request from multiple microservice instances under the target microservice, that is, the target microservice instance.
[0057] In this embodiment, the target microservice instance matching information may include, but is not limited to, content type, received content type, client type, and network connection type.
[0058] Among them, the content type refers to the data format contained in the HTTP request or response, which is specified by the Content-Type header field and is used to tell the server or client how to parse the data in the request body or response body. The received content type refers to the content type that the client can accept, which is specified by the Accept field in the HTTP request header and is used to tell the server the data format that the client wants to receive. The client type refers to the type of client that initiates the request (such as mobile application, desktop application, web browser, etc.), which is determined by the User-Agent field in the HTTP request header or other custom headers (such as X-Client-Type) to inform the server of the type of client. The network connection type refers to the network environment currently used by the client, including WiFi, cellular data, wired network, etc., which is usually obtained through the API provided by the device and can be passed to the API gateway in the request through a custom header (such as X-Network-Type).
[0059] Step S200, based on the candidate microservice instance target microservice instance matching information, matching the target microservice instance corresponding to the candidate microservice instance inbound request from multiple microservice instances under the candidate microservice instance target microservice;
[0060] It should be noted that there are generally multiple microservice instances set up under the same microservice, and they are usually distributed in different servers or containers.
[0061] In this embodiment, although multiple microservice instances under the same microservice share business logic and code base, due to differences in deployment environment, resource allocation, hardware configuration, etc., each microservice instance under the same microservice has different performance characteristics and is suitable for processing different types of inbound requests.
[0062] For example, some microservice instances are equipped with a high-performance JSON (JavaScript Object Notation) parsing library that can efficiently process data in JSON format, and is suitable for processing inbound requests with content types in JSON format. Another example is that some microservice instances are configured with an XML (Extensible Markup Language) generation library that can correctly generate and return XML responses, and is suitable for processing inbound requests with content types in XML format. Another example is that some microservice instances are loaded with modules that optimize image compression and transmission, which can compress and transmit images in exchange for faster loading time and lower data consumption, and are suitable for processing inbound requests with network connection types of cellular networks or client types of mobile applications.
[0063] In this embodiment, if Figure 2 As shown, step S200 may include steps S210 to S220:
[0064] Step S210, obtaining microservice instance matching conditions pre-set for each microservice instance under the target microservice of the candidate microservice instance, and comparing the target microservice instance matching information of the candidate microservice instance with the microservice instance matching conditions corresponding to each microservice instance to obtain a comparison result corresponding to each microservice instance;
[0065] Step S220: According to the comparison results corresponding to the microservice instances, a target microservice instance corresponding to the inbound request of the candidate microservice instance is determined from the microservice instances.
[0066] In this embodiment, a matching condition for determining whether an incoming request is suitable for being processed by the microservice instance, that is, a microservice instance matching condition, is pre-set for each microservice instance.
[0067] Exemplarily, the micro-service instance matching condition may be: the client type corresponding to the inbound request is a mobile application, and the network connection type is a cellular network.
[0068] In this embodiment, comparing the target micro-service instance matching information with the micro-service instance matching conditions corresponding to each micro-service instance means: determining whether the target micro-service instance matching information meets the micro-service instance matching conditions corresponding to each micro-service instance.
[0069] It is not difficult to understand that when the target micro-service instance matching information meets the micro-service instance matching condition corresponding to a certain micro-service instance, it indicates that this micro-service instance is suitable for processing this inbound request, and the API gateway can route this inbound request to this micro-service instance for processing.
[0070] Exemplarily, the target micro-service instance matching information includes the content type and the received content type corresponding to inbound request A. Among them, the content type is in JSON format, and the received content type is in JSON format. Under target micro-service B corresponding to inbound request A, micro-service instance B1 is configured with a JSON generation library and a JSON parsing library. The corresponding micro-service instance matching condition is: the content type corresponding to the inbound request is in JSON format, and the received content type is in JSON format. At this time, the target micro-service instance matching information meets the micro-service instance matching condition corresponding to micro-service instance B1, that is, micro-service instance B1 is suitable for processing inbound request A, and the API gateway can route inbound request A to micro-service instance B1 for processing.
[0071] In this embodiment, as Figure 3 shown, step S220 may include steps S221 to S222:
[0072] Step S221, according to the comparison results corresponding to each micro-service instance, use the micro-service instances among each micro-service instance whose micro-service instance matching conditions are met by the target micro-service instance matching information of the alternative micro-service instance as alternative micro-service instances;
[0073] Step S222, when the number of alternative micro-service instances is one, determine the alternative micro-service instance as the target micro-service instance corresponding to the inbound request of the alternative micro-service instance.
[0074] Further, after step S221, step S223 may also be included:
[0075] Step S223, when the number of alternative micro-service instances is greater than one, based on a preset micro-service instance selection strategy, determine the target micro-service instance corresponding to the inbound request of the alternative micro-service instance from each alternative micro-service instance.
[0076] In this embodiment, considering that among multiple microservice instances under the same microservice, some microservice instances may be set with the same or nearly the same microservice instance matching conditions when setting the microservice instance matching conditions, resulting in that the target microservice instance matching information extracted from the inbound request may simultaneously meet the microservice instance matching conditions corresponding to multiple microservice instances. After determining the comparison results corresponding to each microservice instance in this embodiment, the microservice instances whose microservice instance matching conditions are met by the target microservice instance matching information are used as candidate microservice instances. Then, the number of candidate microservice instances is counted. When the number of candidate microservice instances is one (that is, only one microservice instance under the target microservice has its microservice instance matching condition met by the target microservice matching information), the only candidate microservice instance is determined as the target microservice instance corresponding to the inbound request. When the number of candidate microservice instances is greater than one (that is, more than one microservice instance under the target microservice has its microservice instance matching condition met by the target microservice matching information), based on a preset service instance selection strategy (such as the least number of connections, the highest priority, random, etc.), the target microservice instance corresponding to the inbound request is further determined from each candidate microservice instance.
[0077] Exemplarily, in a feasible implementation manner, the preset microservice instance selection strategy is: preferentially select candidate microservice instances with a smaller number of connections;
[0078] The step of determining the target microservice instance corresponding to the candidate microservice instance inbound request from each candidate microservice instance based on the preset microservice instance selection strategy in step S223 may include steps A10 to A20:
[0079] Step A10, obtain the number of connections and the connection number threshold of each candidate microservice instance, and use the candidate microservice instances with the number of connections less than the connection number threshold among each candidate microservice instance as candidate microservice instances to be selected;
[0080] Step A20, determine the microservice instance with the smallest number of connections among the candidate microservice instances to be selected as the target microservice instance corresponding to the candidate microservice instance inbound request.
[0081] This embodiment follows the strategy of preferentially selecting alternative microservice instances with a smaller number of connections. The alternative microservice instances with a number of connections less than the connection number threshold are used as candidate microservice instances. Then, the microservice instance with the smallest number of connections is selected from the candidate microservice instances as the target microservice instance corresponding to the inbound request, so as to avoid the situation where some microservice instances in the candidate microservice instances are overloaded while other microservice instances are idle, achieve a more uniform load distribution, prevent individual instances from experiencing performance degradation or crashes due to excessive load, improve the utilization efficiency of resources, enable the system to process new requests faster, reduce the user waiting time, and then enhance the user satisfaction and experience quality, reduce unnecessary hardware costs, improve the overall response speed of the system, and enhance the overall stability and reliability of the system.
[0082] It can be understood that when the number of microservice instances with the smallest number of connections in the candidate microservice instances is greater than one, the microservice instance with the largest connection number threshold can be preferentially selected from each microservice instance with the smallest number of connections as the target microservice instance corresponding to the inbound request.
[0083] In the second feasible embodiment, the preset microservice instance selection strategy is: preferentially select alternative microservice instances with higher priorities;
[0084] In step S223, based on the preset microservice instance selection strategy, the steps of determining the target microservice instance corresponding to the inbound request of the alternative microservice instance from each alternative microservice instance may further include steps B10 to B20:
[0085] Step B10, obtain the priorities of each alternative microservice instance, and use the alternative microservice instance with the highest priority among each alternative microservice instance as the candidate microservice instance;
[0086] Step B20, randomly select a microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the alternative microservice instance.
[0087] This embodiment follows the strategy of preferentially selecting alternative microservice instances with higher priorities, uses the alternative microservice instance with the highest priority as the candidate microservice instance, and then randomly selects one from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
[0088] In this embodiment, priorities are set for each microservice instance in advance according to the configuration information and computing resources of each microservice instance. The microservice instance with higher configuration and richer computing resources has a higher priority. Thus, when selecting the target microservice instance, the inbound request is preferentially routed to the microservice instance with a higher priority for processing to ensure the overall processing speed.
[0089] It is not difficult to understand that when the number of candidate microservice instances is one, the only candidate microservice instance can be directly determined as the target microservice instance corresponding to the inbound request. When the number of candidate microservice instances is greater than one, in addition to random selection, it is also possible to further compare the connection counts, CPU loads, etc. of each candidate microservice instance, and select the microservice instance with the fewest connections or the lowest CPU (Central Processing Unit) load as the target microservice instance.
[0090] In the third feasible implementation manner, the preset microservice instance selection strategy is: preferentially select candidate microservice instances with lower CPU loads;
[0091] In step S223, the step of determining the target microservice instance corresponding to the inbound request of the candidate microservice instance based on the preset microservice instance selection strategy may further include steps C10 to C20:
[0092] Step C10, obtain the CPU loads of each candidate microservice instance, and use the candidate microservice instance with the lowest CPU load among each candidate microservice instance as the candidate microservice instance;
[0093] Step C20, randomly select one microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.
[0094] This implementation manner follows the strategy of preferentially selecting candidate microservice instances with lower CPU loads, uses the candidate microservice instance with the lowest CPU load as the candidate microservice instance, and then randomly selects one from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
[0095] It is not difficult to understand that when the number of candidate microservice instances is one, the only candidate microservice instance can be directly determined as the target microservice instance corresponding to the inbound request. When the number of candidate microservice instances is greater than one, in addition to random selection, it is also possible to further compare the connection counts, priorities, etc. of each candidate microservice instance, and select the microservice instance with the fewest connections or the highest priority as the target microservice instance.
[0096] In addition, it is worth mentioning that this embodiment can also perform dynamic weight assignment for each candidate microservice instance, and calculate the dynamic weights of each candidate microservice instance in real time or when needed according to the priorities, connection counts, CPU loads, and even hardware or software configuration information (such as whether there is a configured JSON parsing library, the model type of the hardware, the real-time network status) of each candidate microservice instance, so as to determine the target microservice instance corresponding to the inbound request according to the dynamic weights of each candidate microservice instance.
[0097] Step S300: Obtain the network address corresponding to the alternative microservice instance (the target microservice instance), and route the inbound request of the alternative microservice instance to the alternative microservice instance (the target microservice instance) based on the network address of the alternative microservice instance.
[0098] In this embodiment, after the API mesh determines the target microservice instance from multiple microservice instances under the target microservice, it obtains the network address corresponding to the target microservice instance, and then routes the inbound request to the target microservice instance based on this network address, so as to hand over the inbound request to the target microservice instance for processing.
[0099] Compared with the traditional routing method based on the load balancing algorithm, the present application comprehensively considers various factors (such as content type, received content type, client type, and network connection type) as the basis for microservice instance routing decisions, and performs fine-grained analysis and matching on inbound requests through multi-dimensional matching information, thereby improving the flexibility and accuracy of the API gateway routing decision, achieving accurate microservice instance routing, enabling the API gateway to not only more intelligently select the specific microservice instance most suitable for processing requests, but also significantly improve the system's performance, reliability, and user experience, and then dynamically adapt to different application scenarios, provide more personalized and optimized services, optimize traffic distribution, improve resource utilization and service response speed, and ensure that different types of clients can obtain the best service experience under various network conditions.
[0100] Further, in a feasible implementation manner, the matching information of the alternative microservice instance (the target microservice instance) further includes at least one of the IP address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the inbound request of the alternative microservice instance.
[0101] In this embodiment, the target microservice instance matching information may further include at least one of the IP (Internet Protocol) address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the inbound request. Thus, when selecting a target microservice instance, more dimensions are considered, enabling more fine-grained management of the routing of inbound requests and making the routing decision of the API gateway more flexible and accurate. For example, for an inbound request with an IP address corresponding to City A, it can be routed to a microservice instance deployed in City A for processing, thereby reducing network latency and improving transmission efficiency. For an inbound request with a user identity of an administrator, it can be routed to a microservice instance with a higher security configuration after additional security reinforcement for processing, thereby enhancing the security of operations and reducing risks. For an inbound request with a user identity of a member, it can be routed to a microservice instance with a higher configuration and richer computing resources for processing, thereby enhancing the satisfaction of members with member services. For an inbound request with a request method of GET, it can be routed to a microservice instance responsible for lightweight reading for processing, thereby improving the response speed. For an inbound request with a request method of POST, it can be routed to a microservice instance with stronger writing capabilities for processing, thereby ensuring efficient processing.
[0102] In addition, please refer to Figure 4 , Figure 4 which is a schematic diagram of the module structure of the API gateway in the embodiments of the present application.
[0103] The present application also provides an API gateway, which includes:
[0104] A receiving module 10, configured to extract target microservice instance matching information from the inbound request of the alternative microservice instance and determine the target microservice corresponding to the inbound request of the alternative microservice instance after receiving the inbound request sent by the client. Among them, the alternative microservice instance target microservice instance matching information includes at least one of the content type, received content type, client type, and network connection type corresponding to the inbound request of the alternative microservice instance;
[0105] A matching module 20, configured to match the target microservice instance corresponding to the inbound request of the alternative microservice instance from multiple microservice instances under the target microservice of the alternative microservice instance based on the alternative microservice instance target microservice instance matching information;
[0106] A routing module 30, configured to obtain the network address corresponding to the alternative microservice instance target microservice instance and route the inbound request of the alternative microservice instance to the alternative microservice instance target microservice instance based on the network address of the alternative microservice instance.
[0107] In an embodiment, the matching module 20 is further configured to:
[0108] Obtain the microservice instance matching conditions that have been set in advance for each microservice instance under the alternative microservice instance target microservice, and compare the alternative microservice instance target microservice instance matching information with the microservice instance matching conditions corresponding to each microservice instance to obtain the comparison results corresponding to each microservice instance;
[0109] Determine the target microservice instance corresponding to the inbound request of the alternative microservice instance from each microservice instance according to the comparison results corresponding to each microservice instance.
[0110] In one embodiment, the matching module 20 is further configured to:
[0111] According to the comparison results corresponding to each microservice instance, use the microservice instances whose microservice instance matching conditions are satisfied by the alternative microservice instance target microservice instance matching information among each microservice instance as alternative microservice instances;
[0112] In the case where the number of alternative microservice instances is one, determine the alternative microservice instance as the target microservice instance corresponding to the inbound request of the alternative microservice instance.
[0113] In one embodiment, the matching module 20 is further configured to:
[0114] In the case where the number of alternative microservice instances is greater than one, based on a preset microservice instance selection strategy, determine the target microservice instance corresponding to the inbound request of the alternative microservice instance from each alternative microservice instance.
[0115] In one embodiment, the preset microservice instance selection strategy is: preferentially select alternative microservice instances with a smaller number of connections;
[0116] The matching module 20 is further configured to:
[0117] Obtain the number of connections and the connection number threshold of each alternative microservice instance, and use the alternative microservice instances with a connection number less than the connection number threshold among each alternative microservice instance as candidate microservice instances;
[0118] From the alternative microservice instance candidate microservice instances, determine the microservice instance with the smallest number of connections as the target microservice instance corresponding to the inbound request of the alternative microservice instance.
[0119] In one embodiment, the preset microservice instance selection strategy is: preferentially select alternative microservice instances with a higher priority;
[0120] The matching module 20 is further configured to:
[0121] Obtain the priority of each alternative microservice instance, and use the alternative microservice instance with the highest priority among each alternative microservice instance as a candidate microservice instance;
[0122] Randomly select one microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.
[0123] In one embodiment, the preset microservice instance selection policy is: preferentially select the candidate microservice instance with a lower CPU load;
[0124] The matching module 20 is further configured to:
[0125] Obtain the CPU load of each candidate microservice instance, and use the candidate microservice instance with the lowest CPU load among each candidate microservice instance as the candidate microservice instance;
[0126] Randomly select one microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.
[0127] In one embodiment, the matching information of the candidate microservice instance and the target microservice instance further includes at least one of the IP address, user identity, query parameter, request method, timestamp, device information, and path pattern corresponding to the inbound request of the candidate microservice instance.
[0128] The API gateway provided by this application adopts the microservice instance routing method in the above embodiment, which can solve the technical problems that the routing decision of the API gateway in the related art is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the API gateway provided by this application are the same as those of the microservice instance routing method in the above embodiment, and other technical features of this API gateway are the same as those disclosed in the microservice instance routing method in the above embodiment, which will not be elaborated here.
[0129] In addition, please refer to Figure 5 , Figure 5 which is a schematic diagram of the device structure of the hardware operating environment involved in the microservice instance routing method of the embodiment of this application.
[0130] This application also provides a computing service device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the steps of the microservice instance routing method in the above embodiment.
[0131] Next, refer to Figure 5 , which shows a schematic diagram of the structure of a computing service device suitable for implementing the embodiment of this application. The computing service device in the embodiment of this application may include, but is not limited to, physical servers, virtual machines, cloud servers, or any computing service device capable of implementing the above functions. Figure 5The illustrated computing service device is merely an example and should not impose any limitations on the functions and scope of use of the embodiments of the present application.
[0132] As Figure 5 shown, the computing service device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory 1002 or the program loaded from the storage device 1003 into the random access memory 1004. In the random access memory 1004, various programs and data required for the operation of the computing service device are also stored. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. An input / output interface 1006 is also connected to the bus. Generally, the following systems may be connected to the input / output interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the computing service device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows a computing service device having various systems, it should be understood that it is not required to implement or have all the shown systems. Instead, more or fewer systems may be implemented or had.
[0133] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device, or installed from the storage device 1003, or installed from the read-only memory 1002. When the computer program is executed by the processing device 1001, the above functions defined in the method of the embodiments disclosed in the present application are executed.
[0134] The computing service device provided by the present application adopts the microservice instance routing method in the above embodiments, which can solve the technical problems that the routing decision of the API gateway in the related art is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the computing service device provided by the present application are the same as those of the microservice instance routing method in the above embodiments, and other technical features in the computing service device are the same as those disclosed in the method of the above embodiments, and will not be elaborated herein.
[0135] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.
[0136] The above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art within the technical scope disclosed in this application can easily think of changes or substitutions, which should all be covered within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the above-mentioned claims.
[0137] In addition, this application also provides a storage medium, which is a computer-readable storage medium and has computer-readable program instructions (i.e., computer programs) stored thereon. The computer-readable program instructions are used to execute the steps of the microservice instance routing method in the above embodiments.
[0138] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memories, read-only memories, erasable programmable read-only memories, optical fibers, portable compact disk read-only memories, optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or combined with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0139] The above computer-readable storage medium can be included in the API gateway; or it can exist alone without being assembled into the API gateway.
[0140] The above computer-readable storage medium carries one or more programs, which, when executed by the API gateway, cause the API gateway to: after receiving an inbound request sent by a client, extract target microservice instance matching information from the alternative microservice instance inbound request and determine the target microservice corresponding to the alternative microservice instance inbound request, where the alternative microservice instance target microservice instance matching information includes at least one of the content type, received content type, client type, and network connection type corresponding to the alternative microservice instance inbound request; based on the alternative microservice instance target microservice instance matching information, match out the target microservice instance corresponding to the alternative microservice instance inbound request from multiple microservice instances under the alternative microservice instance target microservice; obtain the network address corresponding to the alternative microservice instance target microservice instance, and route the alternative microservice instance inbound request to the alternative microservice instance target microservice instance based on the alternative microservice instance network address.
[0141] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).
[0142] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0143] The modules described in the embodiments of the present application can be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.
[0144] The storage medium provided by the present application stores computer-readable program instructions for performing the steps of the above-mentioned microservice instance routing method, which can solve the technical problems that the routing decision of the API gateway in the related art is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the storage medium provided by the present application are the same as those of the microservice instance routing method in the above embodiments, and will not be elaborated here.
[0145] In addition, an embodiment of the present application also provides a program product, which is a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps of the microservice instance routing method in the above embodiments.
[0146] The program product provided by the present application can solve the technical problems that the routing decision of the API gateway in the related art is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the program product provided by the embodiment of the present application are the same as those of the microservice instance routing method in the above embodiments, and will not be elaborated here.
[0147] The above are only some embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structural transformation made under the technical concept of the present application by using the content of the specification and drawings of the present application, or any direct / indirect application in other related technical fields, is included in the patent protection scope of the present application.
Claims
1. A microservice instance routing method, characterized in that, The method is applied to an API gateway, and the method includes: After receiving an inbound request sent by a client, extracting target microservice instance matching information from the inbound request, and determining a target microservice corresponding to the inbound request. Wherein, the target microservice instance matching information includes a network connection type corresponding to the inbound request, and the network connection type is used to reflect the current network environment of the client. The network connection type includes WiFi, cellular data, or wired network, and the network connection type is passed to the API gateway through a custom header in the inbound request; Based on the target microservice instance matching information, matching a target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice; Obtaining a network address corresponding to the target microservice instance, and routing the inbound request to the target microservice instance based on the network address; Wherein, the step of matching a target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice based on the target microservice instance matching information includes: Obtaining microservice instance matching conditions respectively set in advance for each microservice instance under the target microservice, and comparing the target microservice instance matching information with the microservice instance matching conditions corresponding to each microservice instance to obtain comparison results corresponding to each microservice instance; Determining a target microservice instance corresponding to the inbound request from each microservice instance according to the comparison results corresponding to each microservice instance.
2. The microservice instance routing method according to claim 1, wherein, The step of determining a target microservice instance corresponding to the inbound request from each microservice instance according to the comparison results corresponding to each microservice instance includes: According to the comparison results corresponding to each microservice instance, taking the microservice instances whose microservice instance matching conditions are satisfied by the target microservice instance matching information among each microservice instance as candidate microservice instances; In the case where the number of candidate microservice instances is one, determining the candidate microservice instance as the target microservice instance corresponding to the inbound request.
3. The microservice instance routing method according to claim 2, wherein, After the step of taking the microservice instances whose microservice instance matching conditions are satisfied by the target microservice instance matching information among each microservice instance as candidate microservice instances according to the comparison results corresponding to each microservice instance, it further includes: In the case where the number of candidate microservice instances is greater than one, determining a target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy.
4. The microservice instance routing method according to claim 3, characterized in that, The preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a smaller number of connections; The step of determining a target microservice instance corresponding to the inbound request from each candidate microservice instance based on the preset microservice instance selection strategy includes: Obtaining the number of connections and a connection number threshold of each candidate microservice instance, and taking the candidate microservice instances with a number of connections less than the connection number threshold among each candidate microservice instance as candidate microservice instances to be selected; Determining the microservice instance with the smallest number of connections among the candidate microservice instances to be selected as the target microservice instance corresponding to the inbound request.
5. The microservice instance routing method according to claim 3, wherein The preset microservice instance selection strategy is: preferentially select alternative microservice instances with higher priorities; The step of determining the target microservice instance corresponding to the inbound request from each alternative microservice instance based on the preset microservice instance selection strategy includes: Obtain the priorities of each alternative microservice instance, and select the alternative microservice instance with the highest priority from each alternative microservice instance as the candidate microservice instance; Randomly select one microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
6. The microservice instance routing method according to claim 3, wherein The preset microservice instance selection strategy is: preferentially select alternative microservice instances with lower CPU loads; The step of determining the target microservice instance corresponding to the inbound request from each alternative microservice instance based on the preset microservice instance selection strategy includes: Obtain the CPU loads of each alternative microservice instance, and select the alternative microservice instance with the lowest CPU load from each alternative microservice instance as the candidate microservice instance; Randomly select one microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request.
7. The microservice instance routing method according to any one of claims 1 to 6, characterized in that, The target microservice instance matching information further includes at least one of the IP address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the inbound request.
8. An API gateway, characterized in that, The API gateway includes: A receiving module, configured to, after receiving an inbound request sent by a client, extract target microservice instance matching information from the inbound request, and determine the target microservice corresponding to the inbound request, where the target microservice instance matching information includes the network connection type corresponding to the inbound request, and the network connection type is used to reflect the current network environment of the client, and the network connection type includes WiFi, cellular data, or wired network, and the network connection type is passed to the API gateway through a custom header in the inbound request; A matching module, configured to match the target microservice instance corresponding to the inbound request from multiple microservice instances under the target microservice based on the target microservice instance matching information; A routing module, configured to obtain the network address corresponding to the target microservice instance, and route the inbound request to the target microservice instance based on the network address; Wherein, the matching module is further configured to: Obtain the microservice instance matching conditions previously set for each microservice instance under the target microservice respectively, and compare the target microservice instance matching information with the microservice instance matching conditions corresponding to each microservice instance to obtain the comparison results corresponding to each microservice instance; Determine the target microservice instance corresponding to the inbound request from each microservice instance according to the comparison results corresponding to each microservice instance.
9. A computing service device, characterized in that, The computing service device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the microservice instance routing method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Operating method for micro-service network system and micro-service network system
CN117118965A
Routing method and device of service request, equipment and storage medium
CN119583655A