A Kong gateway configuration, routing matching method and device, computer equipment and storage medium

By introducing the radix tree routing matching solution in the Kong gateway, the routing matching efficiency is optimized, the performance bottleneck problem of the traditional Kong gateway under high concurrent requests is solved, the system performance is improved and the operation and maintenance costs are reduced.

CN119420695BActive Publication Date: 2025-10-21E-SURFING DIGITAL LIFE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411646911.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-10-21
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

When traditional Kong gateways process a large number of requests, the delays and performance bottlenecks caused by linear searches cannot meet the needs of efficient routing matching.

Method used

The radix tree is used as the core data structure for route matching. By encapsulating the radix tree route collection, construction and query functions, the initialization process of the Kong gateway is optimized, an efficient route matching structure is constructed, and the radix tree is used for route matching.

Benefits of technology

It significantly improves the matching speed of API requests, reduces response time, reduces system load, and reduces enterprise operation and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119420695B_ABST
    Figure CN119420695B_ABST
Patent Text Reader

Abstract

The application provides a configuration method of a Kong gateway. The method comprises: encapsulating a radix tree routing collection function, a radix tree construction function and a radix tree query function; embedding the radix tree routing collection function and the radix tree construction function in an initialization function of the Kong gateway, so that in the initialization process of the Kong gateway, when traversing native routing information in a database, the radix tree routing collection function is used to obtain radix tree routing information corresponding to each native routing information, and then the radix tree construction function is used to obtain a target radix tree according to each radix tree routing information; and replacing routing matching code in a routing query function of the Kong gateway with the radix tree query function, so that when the Kong gateway receives a query request, if no successful matching is found in the cache, the radix tree query function is used to process the query request. The scheme enables the Kong gateway to use a radix tree as a core data structure for routing matching, optimizes memory usage and significantly improves overall performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a Kong gateway configuration, route matching method, apparatus, computer equipment, and storage medium. Background Art

[0002] With the rapid development of the internet and the prevalence of microservices architectures, the number and complexity of enterprise APIs have increased significantly, leading to a growing demand for efficient routing and matching mechanisms. Kong, an excellent API gateway originally built on Nginx and Lua, offers efficient request processing and powerful functionality suitable for applications and services of all sizes. Backed by enterprise-grade technical support, it quickly gained popularity among enterprise developers. However, with the continuous growth of user traffic and the number of APIs, the simple linear search of traditional routing and matching solutions is limited in its ability to handle large numbers of requests, resulting in latency and performance bottlenecks. Summary of the Invention

[0003] The purpose of this application is to solve at least one of the above-mentioned technical defects, and in particular to provide a set of Kong gateway configuration and route matching solutions that improve route matching efficiency, optimize system performance, and reduce enterprise operation and maintenance costs.

[0004] In a first aspect, the present application provides a method for configuring a Kong gateway, including:

[0005] Encapsulates the radix tree routing collection function, radix tree construction function and radix tree query function; wherein, the input of the radix tree routing collection function is the native routing information of the Kong gateway, the radix tree routing collection function is used to extract the target element from the native routing information and convert the target element into radix tree routing information, the radix tree construction function is used to pass all the input radix tree routing information into the new function provided by the radix tree module of the Lua environment to build the target radix tree, and the radix tree query function is used to pass the input target url and routing matching items into the matching function provided by the radix tree module of the Lua environment to use the target radix tree for routing matching;

[0006] The radix tree routing collection function and the radix tree construction function are embedded in the initialization function of the Kong gateway, so that during the initialization process of the Kong gateway, when traversing the native routing information in the database, the radix tree routing collection function is used to obtain the radix tree routing information corresponding to each native routing information, and then the radix tree construction function is used to obtain the target radix tree according to each radix tree routing information;

[0007] The radix tree query function replaces the route matching code in the route query function of the Kong gateway, so that when the Kong gateway receives a query request, if it is not successfully matched in the cache, it uses the radix tree query function to process the query request.

[0008] In one embodiment, the Kong gateway configuration method further includes:

[0009] Encapsulate the radix tree clearing function and embed the radix tree clearing function into the initialization function of the Kong gateway, so that the Kong gateway calls the radix tree clearing function at the beginning of initialization to clear the current target radix tree.

[0010] In one embodiment, the radix tree query function is also used to return the queried routing information according to the return information template after a successful query.

[0011] In one embodiment, the return information template is obtained based on the native routing query return template of the Kong gateway.

[0012] In a second aspect, the present application provides a route matching method for a Kong gateway. The Kong gateway is configured according to the configuration method of the Kong gateway in any of the above embodiments. The route matching method includes:

[0013] In response to a query request, the initialization function is called for initialization. During the initialization process, the native routing information in the database is traversed. The radix tree routing collection function converts each native routing information into the corresponding radix tree routing information during the traversal process. The radix tree construction function obtains the target radix tree based on each radix tree routing information. The query request includes the target URL and the routing matching item.

[0014] Check whether there is routing information corresponding to the query request in the cache;

[0015] If so, the queried routing information is returned;

[0016] If not, the query request is input into the routing query function.

[0017] In one embodiment, a radix tree clearing function is embedded in the initialization function, and the radix tree clearing function is used to clear the current target radix tree at the beginning of initialization. The route matching method of the Kong gateway also includes:

[0018] When the native routing information in the database changes, call the initialization function again for initialization.

[0019] In one embodiment, the route matching method further includes:

[0020] After the route query function is successfully queried, the result returned by the route query function is stored in the cache.

[0021] In a third aspect, the present application provides a route matching device for a Kong gateway. The Kong gateway is configured according to the configuration method of the Kong gateway described in any of the above embodiments. The route matching device includes:

[0022] The response module is used to call the initialization function to initialize in response to the query request; during the initialization process, the native routing information in the database will be traversed, and the radix tree routing collection function will convert each native routing information into the corresponding radix tree routing information during the traversal process. The radix tree construction function will obtain the target radix tree based on each radix tree routing information. The query request includes the target URL and the route matching item;

[0023] The cache query module is used to query whether the routing information corresponding to the query request exists in the cache;

[0024] A first processing module is configured to return the queried routing information if routing information corresponding to the query request exists in the cache;

[0025] The second processing module is configured to input the query request into the routing query function if routing information corresponding to the query request does not exist in the cache.

[0026] In a fourth aspect, the present application provides a computer device comprising one or more processors and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the steps of the Kong gateway configuration method or the Kong gateway route matching method described in any of the above embodiments are executed.

[0027] In a fifth aspect, the present application provides a computer-readable storage medium, which stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the Kong gateway configuration method or the Kong gateway route matching method described in any of the above embodiments.

[0028] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0029] The solution in this application optimizes the initialization process of the Kong gateway, embedding the radix tree routing collection function and the radix tree construction function into the gateway initialization function. The radix tree construction preparation is completed when the native routing information is initially traversed, so that the gateway has an efficient routing matching structure before formally processing the request. When the processing request arrives, the constructed target radix tree can be used for routing matching. Since the radix tree is used as the core data structure for Kong gateway routing matching, memory usage is optimized, the matching speed of API requests is significantly improved, and the response time of requests is reduced. When processing high-concurrency requests, it can effectively reduce the system load and improve overall performance, thereby effectively reducing the enterprise's operation and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 these drawings without paying any creative labor.

[0031] Figure 1 This is a schematic diagram of the structure of the radix tree;

[0032] Figure 2 A flowchart of a method for configuring a Kong gateway according to an embodiment of the present application is provided;

[0033] Figure 3 A flowchart of a route matching method for a Kong gateway provided in one embodiment of the present application;

[0034] Figure 4 This is a performance test result of the route matching method of the Kong gateway in one embodiment of the present application compared with the native Kong gateway under the condition of route matching;

[0035] Figure 5 This is a performance test result of the route matching method of the Kong gateway in one embodiment of the present application compared with the native Kong gateway in the case of route mismatch;

[0036] Figure 6 A diagram of the internal structure of a computer device provided for one embodiment of the present application. DETAILED DESCRIPTION

[0037] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application and do not belong to all the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0038] In the Kong gateway's route matching scheme, during route initialization, all routes in the database are grouped according to matching criteria (for example, routes matching header and host are grouped together, while routes matching method and src are grouped together). During route matching, these routes are traversed through these route groups, utilizing caching and bitwise operations to improve matching efficiency. The cache stores matched routes and returns them directly the next time the same request is encountered; bitwise operations improve the efficiency of request parameter recognition, making it easier to quickly find the corresponding route group. While this is a relatively efficient route matching mechanism in traditional route matching schemes, it essentially requires a traversal of all routes, which can lead to performance bottlenecks in certain situations. For example, if a request doesn't match any route, Kong will traverse all route groups, resulting in a time complexity of O(n) (where n is the number of routes). This significantly reduces route matching efficiency when there are many routes.

[0039] However, if a radix tree is used as the basis for route matching, in the radix tree route matching scheme, each character in a route URL generates a tree node in turn, and a tree path extends from the root node. If multiple routes have the same URL prefix, the tree nodes will be compressed, and the same prefix string will be generated into a tree node to reduce the path length, as shown in the attached example. Figure 1 As shown. When matching routes, it is necessary to perform a breadth traversal of the tree nodes to determine whether each node string is equal to the requested URL. The time complexity is O(k) (k is the length of the URL, which is independent of the number of stored route APIs). It can be seen that the radix tree route matching mechanism has greatly improved performance compared to Kong's native route matching mechanism. In order to integrate the radix tree with the native mechanism of the Kong gateway, the Kong gateway needs to be reconfigured. Therefore, this application provides a configuration method for the Kong gateway, please refer to Figure 2 , including steps S202 to S106.

[0040] S202, encapsulate the radix tree routing collection function, the radix tree construction function and the radix tree query function.

[0041] It can be understood that in a radix tree, routing information consists of a tree path and leaf nodes. The tree path is defined by the routing URL, and the leaf nodes will store routing information with the same URL. This information contains several key elements: hosts, methods, and metadata (where metadata can store routing service, header, and other elements). The native routing information of the Kong gateway already contains these elements. Therefore, in order to convert the native routing information into radix tree routing information, the radix tree routing collection function needs to be encapsulated in this embodiment. The input of the radix tree routing collection function is the native routing information of the Kong gateway. The radix tree routing collection function is used to extract the target element from the native routing information and convert the target element into radix tree routing information. The target element here refers to the element used to construct the leaf node of the radix tree. The radix tree routing collection function can collect the target elements, convert them into radix tree routing information and store them in an array.

[0042] After obtaining the means to collect radix tree routing information, it is necessary to configure the means to construct the radix tree. Therefore, this embodiment also requires encapsulating a radix tree construction function. The Kong Gateway is a gateway product developed in the Lua language. Within the Lua environment, there is an open-source module called lua-resty-radixtree, which provides an API for constructing a routing radix tree and can perform route matching based on the constructed radix tree. The lua-resty-radixtree module provides the new() function and the match() function, respectively, for radix tree construction and route matching. This open-source module is referred to as the radix tree module in this embodiment. The new() function is called the new function. The new function constructs a corresponding radix tree, i.e., the target radix tree, based on all input radix tree routing information. This target radix tree can be used in the route matching phase of the Kong Gateway. The new function is encapsulated within the radix tree construction function. The match() function is called the matching function. Its input is the URL to be queried (i.e., the target URL) and the route matching items. The matching function completes route matching based on the constructed target radix tree. Route matching items are special attributes carried in the routing information, such as method, host, and paths. The matching function will be encapsulated into the radix tree query function.

[0043] S204, embed the radix tree routing collection function and the radix tree construction function into the initialization function of the Kong gateway, so that during the initialization process of the Kong gateway, when traversing the native routing information in the database, the radix tree routing collection function is used to obtain the radix tree routing information corresponding to each native routing information, and then the radix tree construction function is used to obtain the target radix tree according to each radix tree routing information.

[0044] It can be understood that when a request arrives, the Kong gateway will call the build_router() function in handler.lua to initialize. build_router() is the initialization function referred to in this embodiment. The radix tree routing collection function and the radix tree construction function are embedded in the initialization function of the Kong gateway. Its core principle is to use this key stage of gateway initialization to complete the radix tree-related preparations in advance. During the initialization process, the gateway usually traverses the native routing information in the database. At this time, the embedded radix tree routing collection function can process each native routing information in real time when traversing it, and extract the corresponding radix tree routing information. Then after the traversal is completed, the radix tree construction function will build the target radix tree based on all the generated radix tree routing information.

[0045] S206, replacing the route matching code in the route query function of the Kong gateway with the radix tree query function, so that when the Kong gateway receives a query request, if it fails to successfully match in the cache, it uses the radix tree query function to process the query request.

[0046] It can be understood that in the Kong gateway, if the routing information is not found in the cache, the find_route() function in router.lua will be called to perform routing matching. The core process of this function is as follows: first, the routing matching items in the request are analyzed, and then the routing query is performed in the specified routing group according to the routing matching items. After the query is successful, the routing information is returned. This embodiment needs to replace the code corresponding to the core process with the radix tree query function encapsulated in step S202 of this embodiment. In this way, when the find_route() function is needed for routing matching, the radix tree query function will be used to process the query request. The radix tree query function can perform routing matching based on the constructed target radix tree to improve matching efficiency.

[0047] Based on the configuration method of the Kong gateway in this embodiment, the initialization process of the Kong gateway is optimized. The radix tree routing collection function and the radix tree construction function are embedded in the gateway initialization function, and the preparation for building the radix tree is completed when the native routing information is initialized and traversed, so that the gateway has an efficient routing matching structure before formally processing the request. When the processing request arrives, the constructed target radix tree can be used for routing matching. Since the radix tree is used as the core data structure for Kong gateway routing matching, memory usage is optimized, the matching speed of API requests is significantly improved, and the response time of requests is reduced. When processing high-concurrency requests, the system load can be effectively reduced, and the overall performance can be improved, thereby effectively reducing the enterprise operation and maintenance costs.

[0048] In one of the embodiments, the configuration method of the Kong gateway also includes: encapsulating the radix tree clearing function, and embedding the radix tree clearing function into the initialization function of the Kong gateway, so that the Kong gateway calls the radix tree clearing function at the beginning of initialization to clear the current target radix tree.

[0049] It is understandable that when the native routing information in the Kong gateway's database is modified, the Kong gateway will trigger the initialization function to reinitialize, which means it will need to re-traverse the native routing information in the database. In order for the target radix tree in this embodiment to be updated accordingly, the radix tree clearing function needs to be used to clear the current target radix tree when the initialization function starts running. The location where the radix tree clearing function is embedded in the Kong gateway needs to ensure that it can run before the radix tree routing collection function, so that the old radix tree can be cleared before the new target radix tree begins to be built.

[0050] In one embodiment, the radix tree query function is also used to return the queried routing information according to the return information template after a successful query.

[0051] It can be understood that after a successful query, the radix tree query function will return the queried routing information to the Kong gateway, and the Kong gateway will store the returned results in the cache to quickly process similar query requests. In order to utilize the native caching mechanism of the Kong gateway, the radix tree query function in this embodiment should fill the query results into the return information template when returning information. The return information template here is the native template of the information returned by the route matching process of the original find_route() function of the Kong gateway. In this way, the Kong gateway can read the route matching results in the return information template based on the original caching mechanism and cache them.

[0052] This application provides a routing matching method for a Kong gateway. The Kong gateway is configured according to the configuration method of the Kong gateway in any of the above embodiments. Figure 3 , the routing matching method includes steps S302 to S308.

[0053] S302: In response to a query request, the initialization function is called to initialize the query. During the initialization process, the native routing information in the database is traversed. The radix tree routing collection function converts each native routing information into corresponding radix tree routing information during the traversal process. The radix tree construction function obtains the target radix tree based on each radix tree routing information. The query request includes the target URL and the route matching item.

[0054] It can be understood that when the Kong gateway receives a query request, it first calls the initialization function to perform a comprehensive initialization operation. During the initialization process, the native routing information in the database is processed. The radix tree routing collection function plays a role here. The input of the radix tree routing collection function is the native routing information of the Kong gateway. The radix tree routing collection function is used to extract the target element from the native routing information and convert the target element into radix tree routing information. The target element here refers to the element used to construct the leaf node of the radix tree. The radix tree routing collection function can collect the target elements, convert them into radix tree routing information and store them in an array. The target radix tree constructed in this way will have efficient routing matching capabilities, and can quickly match the target URL and routing matching items in the query request in subsequent steps.

[0055] S304: Check whether there is routing information corresponding to the query request in the cache.

[0056] It is understandable that in actual network application scenarios, many requests may have a certain degree of repetitiveness. For example, the same user may visit the same page or perform the same operation multiple times in a short period of time. By setting up a cache mechanism in the gateway and storing the corresponding routing information in the cache after processing each query request, the next time the same or similar query request is received, the routing information can be directly obtained from the cache without having to re-perform a series of operations such as traversing the native routing information in the database, building a radix tree, and performing complex routing matching. This can greatly save request processing time and improve the overall operating efficiency of the gateway. Therefore, when the routing information is queried in the cache, the process can directly proceed to step S306 to return the queried routing information to the user. Otherwise, it is necessary to use the routing query function to process the query request.

[0057] S306: If yes, return the queried routing information.

[0058] It is understandable that if a matching route is found in the cache, it means that a similar request has been processed before. Therefore, directly returning this already determined route can avoid unnecessary route matching operations and improve request processing efficiency.

[0059] S308: If not, input the query request into the routing query function.

[0060] It can be understood that after querying the cache in step S304, if it is found that the routing information corresponding to the query request does not exist in the cache, then it is necessary to proceed to step S308, that is, input the query request into the routing query function. The principle is that since no matching routing information is found in the cache, this means that the current query request may be a new and unprocessed request, or the previously stored routing information cannot be correctly obtained due to reasons such as cache expiration. Therefore, a complete routing matching operation needs to be performed through the routing query function. The code corresponding to the matching in the routing query function has been replaced with a radix tree query function. In this way, when the routing query function is needed for routing matching, the radix tree query function will be used to process the query request. The radix tree query function can perform routing matching based on the constructed target radix tree, thereby improving matching efficiency.

[0061] In one of the embodiments, a radix tree clearing function is embedded in the initialization function, and the radix tree clearing function is used to clear the current target radix tree at the beginning of initialization. The routing matching method of the Kong gateway also includes: when the native routing information in the database changes, re-calling the initialization function for initialization.

[0062] It is understandable that when the native routing information in the Kong gateway's database is modified, the Kong gateway will trigger the initialization function to reinitialize, which means it will need to re-traverse the native routing information in the database. In order for the target radix tree in this embodiment to be updated accordingly, the radix tree clearing function needs to be used to clear the current target radix tree when the initialization function starts running. The location where the radix tree clearing function is embedded in the Kong gateway needs to ensure that it can run before the radix tree routing collection function, so that the old radix tree can be cleared before the new target radix tree begins to be built.

[0063] In one embodiment, the route matching method further includes: after the route query function successfully queries, storing the result returned by the route query function in a cache.

[0064] It can be understood that after a successful query, the radix tree query function will return the queried routing information to the Kong gateway, and the Kong gateway will store the returned results in the cache to quickly process similar query requests. In order to utilize the native caching mechanism of the Kong gateway, the radix tree query function in this embodiment should fill the query results into the return information template when returning information. The return information template here is the native template of the information returned by the route matching process of the original find_route() function of the Kong gateway. In this way, the Kong gateway can read the route matching results in the return information template based on the original caching mechanism and cache them.

[0065] In order to verify the performance of the Kong gateway in this application, the radix tree version of Kong and the native version of Kong were deployed on servers with the same configuration. Both of them will perform cached route queries before the core process of route matching. To ensure the effectiveness of the performance test, the cache mechanism was uniformly cancelled before the stress test. Then, the stress test tool was used to perform a 5-minute stress test on the two versions. During the stress test, the number of routes of the two was kept consistent, the same interface was called, and the number of threads was adjusted to keep their CPU occupancy at the same level. On this basis, two situations were stress tested separately: the route could be matched and the route could not be matched, and the QPS, average response time and maximum response time at different CPU occupancy rates were recorded. Figure 4 The test results are shown for a case where the number of routes is 100 and the routes are matched. The results show that when the number of routes is small and matching is possible, the radix tree version of Kong improves the performance by an average of 8% compared to the native version of Kong. Figure 5 The following shows the result when the number of routes is 1000 and the routes cannot be matched. Figure 6 The results show that when there are a large number of routes and they cannot be matched, the radix tree version of Kong improves the performance by an average of 240% compared to the native version of Kong.

[0066] The present application provides a route matching device for a Kong gateway. The Kong gateway is configured according to the configuration method of the Kong gateway described in any of the above embodiments. The route matching device includes a response module, a cache query module, a first processing module, and a second processing module.

[0067] The response module is used to respond to the query request and call the initialization function for initialization. During the initialization process, the native routing information in the database will be traversed. The radix tree routing collection function will convert each native routing information into the corresponding radix tree routing information during the traversal process. The radix tree construction function will obtain the target radix tree based on each radix tree routing information. The query request includes the target URL and routing matching items. The cache query module is used to query whether there is routing information corresponding to the query request in the cache. The first processing module is used to return the queried routing information if the routing information corresponding to the query request exists in the cache. The second processing module is used to input the query request into the routing query function if the routing information corresponding to the query request does not exist in the cache.

[0068] For the specific definition of the route matching device of the Kong gateway, please refer to the definition of the route matching method of the Kong gateway above, which will not be repeated here. The various modules in the route matching device of the above-mentioned Kong gateway can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0069] The present application provides a computer device comprising one or more processors and a memory, wherein the memory stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the steps of the Kong gateway configuration method or the Kong gateway route matching method described in any of the above embodiments are executed.

[0070] Schematically, as Figure 6 As shown, Figure 6 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. Figure 6 The computer device 600 includes a processing component 602, which further includes one or more processors, and a memory resource represented by a memory 601 for storing instructions executable by the processing component 602, such as an application. The application stored in the memory 601 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 602 is configured to execute instructions to perform the steps of the Kong gateway configuration method or the Kong gateway route matching method of any of the above embodiments.

[0071] The computer device 600 may further include a power supply component 603 configured to perform power management of the computer device 600 , a wired or wireless network interface 604 configured to connect the computer device 600 to a network, and an input / output (I / O) interface 605 .

[0072] The present application provides a computer-readable storage medium, which stores computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the Kong gateway configuration method or the Kong gateway route matching method described in any of the above embodiments.

[0073] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0074] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referenced to each other.

[0075] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for configuring a Kong gateway, characterized in that: include: Encapsulates a radix tree routing collection function, a radix tree construction function, and a radix tree query function; wherein, the input of the radix tree routing collection function is the native routing information of the Kong gateway, the radix tree routing collection function is used to extract the target element from the native routing information and convert the target element into radix tree routing information, the radix tree construction function is used to pass all the input radix tree routing information into the new function provided by the radix tree module of the Lua environment to build a target radix tree, and the radix tree query function is used to pass the input target URL and routing matching items into the matching function provided by the radix tree module of the Lua environment to use the target radix tree for routing matching; The radix tree routing collection function and the radix tree construction function are embedded in the initialization function of the Kong gateway, so that during the initialization process of the Kong gateway, when traversing the native routing information in the database, the radix tree routing collection function is used to obtain the radix tree routing information corresponding to each native routing information, and then the radix tree construction function is used to obtain the target radix tree according to each radix tree routing information; The radix tree query function replaces the route matching code in the route query function of the Kong gateway, so that when the Kong gateway receives a query request, if it is not successfully matched in the cache, it uses the radix tree query function to process the query request.

2. The Kong gateway configuration method according to claim 1, characterized in that: Also includes: Encapsulate the radix tree clearing function and embed the radix tree clearing function into the initialization function of the Kong gateway, so that the Kong gateway calls the radix tree clearing function at the beginning of initialization to clear the current target radix tree.

3. The configuration method of Kong gateway according to claim 1, characterized in that: The radix tree query function is also used to return the queried routing information according to the return information template after a successful query.

4. The configuration method of Kong gateway according to claim 3, characterized in that: The return information template is obtained based on the native routing query return template of the Kong gateway.

5. A routing matching method for Kong gateway, characterized in that: The Kong gateway is configured according to the Kong gateway configuration method according to any one of claims 1 to 4, and the route matching method includes: In response to a query request, an initialization function is called to initialize; during the initialization process, the native routing information in the database is traversed, and the radix tree routing collection function converts each native routing information into the corresponding radix tree routing information during the traversal process. The radix tree construction function obtains the target radix tree based on each radix tree routing information, and the query request includes the target URL and the routing matching item; Checking whether routing information corresponding to the query request exists in the cache; If so, the queried routing information is returned; If not, the query request is input into the routing query function.

6. The routing matching method of Kong gateway according to claim 5, characterized in that: A radix tree clearing function is embedded in the initialization function, and the radix tree clearing function is used to clear the current target radix tree at the beginning of initialization. The routing matching method of the Kong gateway also includes: When the native routing information in the database changes, the initialization function is called again for initialization.

7. The routing matching method of Kong gateway according to claim 5, characterized in that: Also includes: After the routing query function succeeds in querying, the result returned by the routing query function is stored in a cache.

8. A routing matching device for a Kong gateway, characterized in that: The Kong gateway is configured according to the Kong gateway configuration method according to any one of claims 1 to 4, and the route matching device includes: A response module is configured to call an initialization function to initialize the query request in response to the query request; during the initialization process, the native routing information in the database is traversed, the radix tree routing collection function converts each native routing information into the corresponding radix tree routing information during the traversal process, and the radix tree construction function obtains the target radix tree based on each radix tree routing information, wherein the query request includes the target URL and the routing matching item; A cache query module is used to query whether there is routing information corresponding to the query request in the cache; A first processing module, configured to return the queried routing information if routing information corresponding to the query request exists in the cache; The first processing module is configured to input the query request into a routing query function if routing information corresponding to the query request does not exist in the cache.

9. A computer device, characterized in that: The system comprises one or more processors and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the system performs the steps of the Kong gateway configuration method described in any one of claims 1 to 4 or the Kong gateway route matching method described in any one of claims 5 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the Kong gateway configuration method according to any one of claims 1-4 or the Kong gateway route matching method according to any one of claims 5-7.

Citation Information

Patent Citations

  • API gateway routing entity configuration method and system based on Kong

    CN111385146A

  • Database query method and device, electronic equipment and readable storage medium

    CN116126891A