Micro-service instance routing method, API gateway and computing service equipment

By extracting and utilizing multiple matching information of inbound requests in the API gateway for multi-dimensional matching, the problem of inflexible and accurate routing decisions of the API gateway is solved, and more accurate microservice instance routing and system performance improvements are achieved.

CN120017720AActive Publication Date: 2025-05-16SHENZHEN SMARTCITY TECH DEV GRP CO LTD

Patent Information

Application Number
CN202510473465.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-16
Publication Date
2025-05-16
Estimated Expiration
2045-04-16

AI Technical Summary

Technical Problem

The routing decisions of the API gateway are not flexible and accurate enough, and ignore the specific characteristics and technical conditions of client inbound requests, resulting in the inability to adapt to different application scenarios and user needs.

Method used

By extracting the target microservice instance matching information in the inbound request, including factors such as content type, received content type, client type and network connection type, multi-dimensional matching is performed in the API gateway and accurately route to the most suitable microservice instance.

Benefits of technology

It improves the flexibility and accuracy of API gateway routing decisions, realizes accurate microservice instance routing, improves system performance, reliability and user experience, and optimizes traffic allocation and resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120017720A_ABST
    Figure CN120017720A_ABST
Patent Text Reader

Abstract

The invention discloses a micro-service instance routing method, an API gateway and computing service equipment, and relates to the technical field of API gateways. The method is applied to an API gateway, and comprises the following steps: after an inbound request sent by a client is received, extracting target micro-service instance matching information from the inbound request, and determining a target micro-service corresponding to the inbound request, the target micro-service instance matching information comprises at least one of a content type, a receiving content type, a client type and a network connection type corresponding to the inbound request; based on the target micro-service instance matching information, matching a target micro-service instance corresponding to the inbound and outbound request from a plurality of micro-service instances under a target micro-service; and obtaining a network address corresponding to the target micro-service instance, and routing the inbound request to the target micro-service instance based on the network address. According to the application, the routing decision of the API gateway can be more flexible and accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of API gateway technology, 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, microservice architecture has become one of the important patterns for building large distributed systems. It achieves higher modularity, maintainability and scalability by decomposing applications into a series of independent small services (also known as microservices). However, with the increase in 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. Its routing strategy directly affects the performance of the entire system and user experience.

[0003] Currently, most API gateways use load balancing to select instances 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 uniform distribution of traffic to a certain extent, they ignore the specific characteristics and technical conditions of 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, API gateway and computing service device, aiming to solve the technical problem that the routing decision of API gateway in related technologies is not flexible and accurate enough.

[0005] To achieve the above objectives, the present application provides a microservice instance routing method, which is applied to an API gateway and includes: After receiving an inbound request sent by a client, extract target microservice instance matching information from the inbound request, and determine a target microservice corresponding to the inbound request, wherein the target microservice instance matching information includes at least one of a content type corresponding to the inbound request, a received 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; 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.

[0006] 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: Obtaining microservice instance matching conditions pre-set 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 a comparison result corresponding to each microservice instance; According to the comparison results corresponding to each microservice instance, a target microservice instance corresponding to the inbound request is determined from each microservice instance.

[0007] 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: According to the comparison results corresponding to each microservice instance, a microservice instance whose microservice instance matching condition is satisfied by the target microservice instance matching information is selected as a candidate microservice instance; When the number of the candidate microservice instances is one, the candidate microservice instance is determined as the target microservice instance corresponding to the inbound request.

[0008] In one embodiment, after the step of using, according to the comparison results corresponding to each microservice instance, a microservice instance whose microservice instance matching condition is satisfied by the target microservice instance matching information in each microservice instance as a candidate microservice instance, the step further includes: When the number of the candidate microservice instances is greater than one, based on a preset microservice instance selection strategy, a target microservice instance corresponding to the inbound request is determined from the candidate microservice instances.

[0009] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a smaller number of connections; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: The number of connections and the connection number threshold of each candidate microservice instance are obtained, and a candidate microservice instance having a connection number less than the connection number threshold is selected from each candidate microservice instance as a candidate microservice instance; From the candidate microservice instances, determine the microservice instance with the smallest number of connections as the target microservice instance corresponding to the inbound request.

[0010] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a higher priority; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: Obtain the priority of each candidate microservice instance, and select the candidate microservice instance with the highest priority from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as a target microservice instance corresponding to the inbound request.

[0011] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting an alternative microservice instance with a lower CPU load; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: Obtain the CPU load of each candidate microservice instance, and select the candidate microservice instance with the lowest CPU load from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as a target microservice instance corresponding to the inbound request.

[0012] In one embodiment, the target microservice instance matching information also includes at least one of an IP address, a user identity, a query parameter, a request method, a timestamp, device information, and a path pattern corresponding to the inbound request.

[0013] In addition, to achieve the above purpose, the present application also provides an API gateway, the API gateway comprising: A receiving module, configured to extract target microservice instance matching information from the inbound request after receiving the inbound request sent by the client, and determine the target microservice corresponding to the inbound request, wherein the target microservice instance matching information includes at least one of a content type corresponding to the inbound request, a received content type, a client type, and a network connection type; A matching module, configured to match 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; A routing module is used 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.

[0014] In addition, to achieve the above-mentioned purpose, the present application also provides a computing service device, which includes: a memory, a processor, and a computer program stored in 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.

[0015] The present application provides a microservice instance routing method, an API gateway, and a computing service device, and relates to the field of API gateway technology. 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 the target microservice corresponding to the inbound request, wherein 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 and outbound requests 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.

[0016] Compared with the traditional routing method based on load balancing algorithm, 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 performs fine-grained analysis and matching of inbound requests through multi-dimensional matching information, thereby improving the flexibility and accuracy of API gateway routing decisions and realizing accurate microservice instance routing, so that the API gateway can not only more intelligently select the specific microservice instance that is 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, and optimize traffic distribution, improve resource utilization and service response speed, to ensure that different types of clients can get the best service experience under various network conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.

[0019] Figure 1 This is a flow chart of a microservice instance routing method in an embodiment of the present application; Figure 2 A schematic diagram of the matching process of the target microservice instance in the embodiment of the present application; Figure 3 This is a schematic diagram of a specific matching process of a target microservice instance in an embodiment of the present application; Figure 4 This is a schematic diagram of the module structure of the API gateway in the embodiment of the present application; Figure 5 This 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.

[0020] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0021] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0022] 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.

[0023] Currently, most API gateways use load balancing to select instances from multiple microservice instances under the same microservice to process requests. Common load balancing algorithms include polling, least number of connections, weighted polling, etc. Although these methods can ensure the uniform distribution of traffic to a certain extent, they ignore the specific characteristics and technical conditions of client inbound requests, lack fine-grained analysis and multi-dimensional matching of inbound requests, and make routing decisions inflexible and inaccurate.

[0024] For example, it is difficult for traditional routing strategies to make targeted optimizations for the different needs of mobile applications and web pages, and the differences between WiFi (Wireless Fidelity) and mobile data networks. In addition, when faced with complex business logic and diverse request formats, the existing routing mechanism is too rigid and cannot flexibly respond to rapidly changing application scenarios.

[0025] The main solution of the present application is a microservice instance routing method, which is applied to an API gateway, comprising: 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, wherein 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.

[0026] Compared with the traditional routing method based on load balancing algorithm, 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 performs fine-grained analysis and matching of inbound requests through multi-dimensional matching information, thereby improving the flexibility and accuracy of API gateway routing decisions and realizing accurate microservice instance routing, so that the API gateway can not only more intelligently select the specific microservice instance that is 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, and optimize traffic distribution, improve resource utilization and service response speed, to ensure that different types of clients can get the best service experience under various network conditions.

[0027] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0028] Please refer to Figure 1 , Figure 1 Schematic diagram of the process of microservice instance routing method in the embodiment of the present application.

[0029] In this embodiment, the microservice instance routing method is applied to the API gateway, and the method includes steps S100 to S300: 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; 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.

[0030] 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.

[0031] 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.

[0032] 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).

[0033] 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; 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.

[0034] 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.

[0035] 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.

[0036] In this embodiment, if Figure 2 As shown, step S200 may include steps S210 to S220: 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; 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.

[0037] 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.

[0038] Exemplarily, the microservice 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.

[0039] In this embodiment, comparing the target microservice instance matching information with the microservice instance matching conditions corresponding to each microservice instance means: determining whether the target microservice instance matching information satisfies the microservice instance matching conditions corresponding to each microservice instance.

[0040] It is not difficult to understand that when the target microservice instance matching information meets the microservice instance matching condition corresponding to a certain microservice instance, it indicates that the microservice instance is suitable for processing the inbound request, and the API gateway can route the inbound request to the microservice instance for processing.

[0041] Exemplarily, the target microservice instance matching information includes the content type and the received content type corresponding to the inbound request A, wherein the content type is in JSON format and the received content type is in JSON format. Under the target microservice B corresponding to the inbound request A, the microservice instance B1 is configured with a JSON generation library and a JSON parsing library, and the corresponding microservice 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 point, the target microservice instance matching information satisfies the microservice instance matching condition corresponding to the microservice instance B1, that is, the microservice instance B1 is suitable for processing the inbound request A, and the API gateway can route the inbound request A to the microservice instance B1 for processing.

[0042] In this embodiment, if Figure 3 As shown, step S220 may include steps S221-S222: Step S221, according to the comparison results corresponding to each microservice instance, a microservice instance whose microservice instance matching condition is satisfied by the target microservice instance matching information of the candidate microservice instance is selected as a candidate microservice instance; In step S222, when the number of candidate microservice instances is one, the candidate microservice instance is determined as the target microservice instance corresponding to the candidate microservice instance inbound request.

[0043] Furthermore, after step S221, step S223 may be further included: Step S223: When the number of candidate microservice instances is greater than one, based on a preset microservice instance selection strategy, a target microservice instance corresponding to the candidate microservice instance inbound request is determined from the candidate microservice instances.

[0044] In this embodiment, considering that when setting the microservice instance matching conditions, some microservice instances under the same microservice may be set to have the same or nearly the same microservice instance matching conditions, resulting in that the target microservice instance matching information extracted from the inbound request may simultaneously satisfy the microservice instance matching conditions corresponding to multiple microservice instances. After determining the comparison results corresponding to each microservice instance, this embodiment uses the microservice instance whose microservice instance matching conditions are satisfied by the target microservice instance matching information as the candidate microservice instance, and then counts the number of candidate microservice instances, and in the candidate microservice instance When the number of candidate microservice instances is one (that is, the microservice instance matching condition corresponding to only one microservice instance under the target microservice is satisfied by the target microservice matching information), the only candidate microservice instance is determined as the target microservice instance corresponding to the inbound request, and when the number of candidate microservice instances is greater than one (that is, the microservice instance matching conditions corresponding to more than one microservice instance under the target microservice are satisfied by the target microservice matching information), based on the 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 and outbound request is further determined from each candidate microservice instance.

[0045] Exemplarily, in a feasible implementation, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a smaller number of connections; The step of determining the target microservice instance corresponding to the inbound request of the candidate microservice instance from the candidate microservice instances based on the preset microservice instance selection strategy in step S223 may include steps A10 to A20: Step A10, obtaining the number of connections and the connection number threshold of each candidate microservice instance, and selecting a candidate microservice instance whose number of connections is less than the connection number threshold from among the candidate microservice instances as a candidate microservice instance; Step A20: From the candidate microservice instances, determine the microservice instance with the smallest number of connections as the target microservice instance corresponding to the candidate microservice instance inbound request.

[0046] This implementation follows the strategy of giving priority to selecting alternative microservice instances with smaller numbers of connections, and selects alternative microservice instances with numbers of connections less than the connection number threshold as candidate microservice instances, and then selects the microservice instance with the smallest number of connections from the candidate microservice instances as the target microservice instance corresponding to the inbound request, thereby avoiding the situation where some microservice instances in the candidate microservice instances are overloaded while other microservice instances are idle, achieving more even load distribution, preventing individual instances from experiencing performance degradation or crashes due to excessive load, improving resource utilization efficiency, enabling the system to process new requests faster, reducing user waiting time, and thereby improving user satisfaction and experience quality, reducing unnecessary hardware costs, improving the overall response speed of the system, and enhancing the overall stability and reliability of the system.

[0047] It can be understood that when the number of microservice instances with the smallest number of connections among the candidate microservice instances is greater than one, the microservice instance with the largest connection number threshold can be preferentially selected from the microservice instances with the smallest number of connections as the target microservice instance corresponding to the inbound request.

[0048] In a second feasible implementation, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a higher priority; The step of determining the target microservice instance corresponding to the inbound request of the candidate microservice instance from the candidate microservice instances based on the preset microservice instance selection strategy in step S223 may also include steps B10 to B20: Step B10, obtaining the priority of each candidate microservice instance, and selecting the candidate microservice instance with the highest priority from among the candidate microservice instances as the to-be-selected microservice instance; Step B20: Randomly select a microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.

[0049] This implementation follows the strategy of preferentially selecting a candidate microservice instance with a higher priority, selects the candidate 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.

[0050] In this embodiment, a priority is set for each microservice instance in advance based on the configuration information and computing resources of each microservice instance. The microservice instance with higher configuration and richer computing resources has a higher priority. Therefore, when selecting the target microservice instance, the inbound request is preferentially routed to the microservice instance with higher priority for processing, thereby ensuring the overall processing speed.

[0051] It is not difficult to understand that when the number of microservice instances to be selected is one, the only microservice instance to be selected can be directly determined as the target microservice instance corresponding to the inbound request, and when the number of microservice instances to be selected is greater than one, in addition to random selection, the number of connections, CPU load, etc. of each microservice instance to be selected can be further compared to select the microservice instance with the least number of connections or the lowest CPU (Central Processing Unit) load as the target microservice instance.

[0052] In a third feasible implementation, the preset microservice instance selection strategy is: preferentially selecting an alternative microservice instance with a lower CPU load; The step of determining the target microservice instance corresponding to the inbound request of the candidate microservice instance from the candidate microservice instances based on the preset microservice instance selection strategy in step S223 may also include steps C10 to C20: Step C10, obtaining the CPU load of each candidate microservice instance, and selecting the candidate microservice instance with the lowest CPU load from among the candidate microservice instances as the to-be-selected microservice instance; Step C20: randomly select a microservice instance from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.

[0053] This implementation follows the strategy of giving priority to selecting candidate microservice instances with lower CPU loads, selects the candidate microservice instances with the lowest CPU load as candidate microservice instances, and then randomly selects one from the candidate microservice instances as the target microservice instance corresponding to the inbound request.

[0054] It is not difficult to understand that when the number of microservice instances to be selected is one, the only microservice instance to be selected can be directly determined as the target microservice instance corresponding to the inbound request, and when the number of microservice instances to be selected is greater than one, in addition to random selection, the number of connections, priority, etc. of each microservice instance to be selected can be further compared to select the microservice instance with the least number of connections or the highest priority as the target microservice instance.

[0055] In addition, it is worth mentioning that the present embodiment can also dynamically assign weights to each candidate microservice instance, and calculate the dynamic weight of each candidate microservice instance in real time or when necessary according to the priority, number of connections, CPU load, and even hardware or software configuration information (such as whether a JSON parsing library is configured, the model type of the hardware, the real-time network status), etc. of each candidate microservice instance, so as to determine the target microservice instance corresponding to the inbound and outbound requests according to the dynamic weight of each candidate microservice instance.

[0056] Step S300: Obtain a network address corresponding to a target microservice instance of a candidate microservice instance, and route an inbound request of the candidate microservice instance to the target microservice instance of the candidate microservice instance based on the network address of the candidate microservice instance.

[0057] In this embodiment, after the API grid 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 the network address, thereby handing the inbound request to the target microservice instance for processing.

[0058] Compared with the traditional routing method based on load balancing algorithm, 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 performs fine-grained analysis and matching of inbound requests through multi-dimensional matching information, thereby improving the flexibility and accuracy of API gateway routing decisions and realizing accurate microservice instance routing, so that the API gateway can not only more intelligently select the specific microservice instance that is 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, and optimize traffic distribution, improve resource utilization and service response speed, to ensure that different types of clients can get the best service experience under various network conditions.

[0059] Furthermore, in a feasible implementation manner, the candidate microservice instance target microservice instance matching information also includes at least one of an IP address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the candidate microservice instance inbound request.

[0060] In this embodiment, the target microservice instance matching information may also include at least one of the IP (Internet Protocol) address, user identity, query parameters, request method, timestamp, device information, and path mode corresponding to the inbound request, so that when selecting the target microservice instance, more dimensions are considered, and the routing of the inbound request is managed in a more fine-grained manner, making the routing decision of the API gateway more flexible and accurate. For example, for inbound requests corresponding to the IP address of City A, it can be routed to the microservice instance deployed in City A for processing, thereby reducing network delay and improving transmission efficiency. For inbound requests whose user identity is an administrator, it can be routed to a microservice instance with a higher security configuration after additional security reinforcement, thereby improving the security of the operation and reducing risks. For inbound requests whose user identity is a member, it can be routed to a microservice instance with a higher configuration and richer computing resources for processing, thereby improving member satisfaction with member services. For inbound requests whose request method is GET, it can be routed to a microservice instance responsible for lightweight reading for processing, thereby improving response speed. For inbound requests with a request method of POST, they can be routed to microservice instances with stronger write capabilities for processing, thus ensuring efficient processing.

[0061] In addition, please refer to Figure 4 , Figure 4 This is a schematic diagram of the module structure of the API gateway in the embodiment of the present application.

[0062] The present application also provides an API gateway, which includes: The receiving module 10 is used to extract the target microservice instance matching information from the candidate microservice instance inbound request after receiving the inbound request sent by the client, 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; A matching module 20 is used to match a target microservice instance corresponding to an inbound request of a candidate microservice instance from multiple microservice instances under the target microservice of the candidate microservice instance based on the matching information of the target microservice instance of the candidate microservice instance; The routing module 30 is used to obtain the network address corresponding to the target microservice instance of the candidate microservice instance, and route the candidate microservice instance inbound request to the target microservice instance of the candidate microservice instance based on the network address of the candidate microservice instance.

[0063] In one embodiment, the matching module 20 is further configured to: Obtain the microservice instance matching conditions that are pre-set for each microservice instance under the target microservice of the candidate microservice instance, and compare the target microservice instance matching information of the candidate microservice instance with the microservice instance matching conditions corresponding to each microservice instance to obtain the comparison results corresponding to each microservice instance; According to the comparison results corresponding to each microservice instance, a target microservice instance corresponding to the inbound request of the candidate microservice instance is determined from each microservice instance.

[0064] In one embodiment, the matching module 20 is further configured to: According to the comparison results corresponding to each microservice instance, a microservice instance whose microservice instance matching condition is satisfied by the target microservice instance matching information of the candidate microservice instance is selected as a candidate microservice instance; When the number of candidate microservice instances is one, the candidate microservice instance is determined as the target microservice instance corresponding to the candidate microservice instance inbound request.

[0065] In one embodiment, the matching module 20 is further configured to: When the number of candidate microservice instances is greater than one, based on a preset microservice instance selection strategy, a target microservice instance corresponding to the candidate microservice instance inbound request is determined from the candidate microservice instances.

[0066] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a smaller number of connections; The matching module 20 is also used for: The number of connections and the connection number threshold of each candidate microservice instance are obtained, and a candidate microservice instance having a connection number less than the connection number threshold is selected from each candidate microservice instance as a candidate microservice instance; From the candidate microservice instances, a microservice instance with the smallest number of connections is determined as a target microservice instance corresponding to the inbound request of the candidate microservice instance.

[0067] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting a candidate microservice instance with a higher priority; The matching module 20 is also used for: Obtain the priority of each candidate microservice instance, and select the candidate microservice instance with the highest priority from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.

[0068] In one embodiment, the preset microservice instance selection strategy is: preferentially selecting an alternative microservice instance with a lower CPU load; The matching module 20 is also used for: Obtain the CPU load of each candidate microservice instance, and select the candidate microservice instance with the lowest CPU load from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as the target microservice instance corresponding to the inbound request of the candidate microservice instance.

[0069] In one embodiment, the candidate microservice instance target microservice instance matching information also includes at least one of an IP address, user identity, query parameters, request method, timestamp, device information, and path pattern corresponding to the candidate microservice instance inbound request.

[0070] The API gateway provided by this application adopts the microservice instance routing method in the above embodiment, which can solve the technical problem that the routing decision of the API gateway in the related technology 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 the beneficial effects of the microservice instance routing method in the above embodiment, and the other technical features of the API gateway are the same as the features disclosed by the microservice instance routing method in the above embodiment, which will not be repeated here.

[0071] In addition, please refer to Figure 5 , Figure 5 This 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.

[0072] The present 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 so that the at least one processor can execute the steps of the microservice instance routing method in the above embodiment.

[0073] Reference below Figure 5 , which shows a schematic diagram of the structure of a computing service device suitable for implementing the embodiments of the present application. The computing service device in the embodiments of the present application may include but is not limited to a physical server, a virtual machine, a cloud server, or any computing service device capable of implementing the above functions. Figure 5 The computing service device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0074] like Figure 5As shown, the computing service device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory 1002 or a program loaded from a storage device 1003 to a random access memory 1004. Various programs and data required for the operation of the computing service device are also stored in the random access memory 1004. 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 can 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, Liquid Crystal Display), 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 can allow the computing service device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a computing service device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.

[0075] 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 includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0076] The computing service device provided by this application adopts the microservice instance routing method in the above embodiment, which can solve the technical problem that the routing decision of the API gateway in the related technology is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the computing service device provided by this application are the same as the beneficial effects of the microservice instance routing method in the above embodiment, and the other technical features in the computing service device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0077] It should be understood that the various parts 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 any one or more embodiments or examples in a suitable manner.

[0078] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the above claims.

[0079] In addition, the present application also provides a storage medium, which is a computer-readable storage medium and has computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the steps of the microservice instance routing method in the above embodiment.

[0080] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0081] The computer-readable storage medium may be included in the API gateway; or may exist independently without being assembled into the API gateway.

[0082] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the API gateway, the API gateway: after receiving the inbound request sent by the client, extracts the target microservice instance matching information from the candidate microservice instance inbound request, and determines 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, received content type, client type and network connection type corresponding to the candidate microservice instance inbound request; based on the candidate microservice instance target microservice instance matching information, matches the target microservice instance corresponding to the candidate microservice instance inbound request from multiple microservice instances under the candidate microservice instance target microservice; obtains the network address corresponding to the candidate microservice instance target microservice instance, and routes the candidate microservice instance inbound request to the candidate microservice instance target microservice instance based on the candidate microservice instance target microservice instance matching information;

[0083] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate 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 may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0084] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0085] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0086] The storage medium provided by the present application stores computer-readable program instructions for executing the steps of the above-mentioned microservice instance routing method, which can solve the technical problem that the routing decision of the API gateway in the related technology 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 the beneficial effects of the microservice instance routing method in the above-mentioned embodiment, which will not be repeated here.

[0087] 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, the steps of the microservice instance routing method in the above embodiment are implemented.

[0088] The program product provided by this application can solve the technical problem that the routing decision of the API gateway in the related technology is not flexible and accurate enough. Compared with the prior art, the beneficial effects of the program product provided by the embodiment of this application are the same as the beneficial effects of the microservice instance routing method in the above embodiment, which will not be repeated here.

[0089] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are 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, extract target microservice instance matching information from the inbound request, and determine a target microservice corresponding to the inbound request, wherein the target microservice instance matching information includes at least one of a content type corresponding to the inbound request, a received 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; 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.

2. The microservice instance routing method according to claim 1, characterized in that: 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: Obtaining microservice instance matching conditions pre-set 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 a comparison result corresponding to each microservice instance; According to the comparison results corresponding to each microservice instance, a target microservice instance corresponding to the inbound request is determined from each microservice instance.

3. The microservice instance routing method according to claim 2, characterized in that: 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: According to the comparison results corresponding to each microservice instance, a microservice instance whose microservice instance matching condition is satisfied by the target microservice instance matching information is selected as a candidate microservice instance; When the number of the candidate microservice instances is one, the candidate microservice instance is determined as the target microservice instance corresponding to the inbound request.

4. The microservice instance routing method according to claim 3, characterized in that: After the step of taking, according to the comparison results corresponding to the microservice instances, the microservice instances whose microservice instance matching conditions are satisfied by the target microservice instance matching information in the microservice instances as candidate microservice instances, the step further includes: When the number of the candidate microservice instances is greater than one, based on a preset microservice instance selection strategy, a target microservice instance corresponding to the inbound request is determined from the candidate microservice instances.

5. The microservice instance routing method according to claim 4, characterized in that: The preset microservice instance selection strategy is: give priority to selecting the candidate microservice instance with a smaller number of connections; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: The number of connections and the connection number threshold of each candidate microservice instance are obtained, and a candidate microservice instance having a connection number less than the connection number threshold is selected from each candidate microservice instance as a candidate microservice instance; From the candidate microservice instances, determine the microservice instance with the smallest number of connections as the target microservice instance corresponding to the inbound request.

6. The microservice instance routing method according to claim 4, characterized in that: The preset microservice instance selection strategy is: prioritize the candidate microservice instances with higher priorities; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: Obtain the priority of each candidate microservice instance, and select the candidate microservice instance with the highest priority from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as a target microservice instance corresponding to the inbound request.

7. The microservice instance routing method according to claim 4, characterized in that: The preset microservice instance selection strategy is: give priority to selecting alternative microservice instances with lower CPU load; The step of determining the target microservice instance corresponding to the inbound request from each candidate microservice instance based on a preset microservice instance selection strategy includes: Obtain the CPU load of each candidate microservice instance, and select the candidate microservice instance with the lowest CPU load from among the candidate microservice instances as the candidate microservice instance; A microservice instance is randomly selected from the candidate microservice instances as a target microservice instance corresponding to the inbound request.

8. The microservice instance routing method according to any one of claims 1 to 7, characterized in that: The target microservice instance matching information also includes at least one of an IP address, user identity, query parameters, request method, timestamp, device information, and path mode corresponding to the inbound request.

9. An API gateway, characterized in that: The API gateway includes: A receiving module, configured to extract target microservice instance matching information from the inbound request after receiving the inbound request sent by the client, and determine the target microservice corresponding to the inbound request, wherein the target microservice instance matching information includes at least one of a content type corresponding to the inbound request, a received content type, a client type, and a network connection type; A matching module, configured to match 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; A routing module is used 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.

10. A computing service device, characterized in that: The computing service device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the microservice instance routing method according to any one of claims 1 to 8 when executed by the processor.

Citation Information

Patent Citations

  • On-demand networking service instance autonomous generation and matching method and system

    CN116436923A

  • 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

  • Vehicle-road cooperation apparatus and method, electronic device and storage medium

    WO2021022987A1

Cited By

  • Drug identification information efficient query method and system based on distributed cache

    CN120429327A