Gateway route matching method and device, computer device and readable storage medium
By grouping routing rules by business dimension and using cached indexes for location, and adopting a two-level matching mechanism, the problem of low efficiency in traditional gateway routing matching is solved, thereby improving system performance and response speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU PINGPONG INTELLIGENT TECH CO LTD
- Filing Date
- 2026-05-06
- Publication Date
- 2026-06-02
AI Technical Summary
Traditional gateway routing matching methods are inefficient when faced with a large number of routing rules, leading to increased matching time and impacting system performance and response latency.
The routing rules are grouped according to business dimensions to generate group key values. Fast indexing and location are achieved through a preset cache. A two-level matching mechanism is adopted, which first matches the group and then matches the specific route within the group, replacing the traditional linear traversal method.
Significantly reduces matching time, decreases invalid matches, and improves gateway routing matching efficiency, especially enhancing system performance and throughput in high-concurrency scenarios.
Smart Images

Figure CN122137783A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a gateway routing matching method, apparatus, computer device, and readable storage medium. Background Technology
[0002] Gateway routing matching refers to the process by which a gateway, based on received request information and according to predefined rules, accurately directs requests to the corresponding backend services. Gateway routing matching plays a crucial role in system architecture, fulfilling multiple key functions. For example, at the service level, it enables decoupling and isolation, allowing services to be developed, deployed, and maintained independently, reducing system coupling; in terms of security, it can perform security checks and filtering on requests during routing matching, blocking illegal requests, and so on.
[0003] In a microservice architecture and API (Application Programming Interface) gateway system, route matching is one of the core functions. When a request arrives at the gateway, it needs to traverse all registered routing rules, match them based on path, method, parameters, and other conditions, and find the corresponding backend service for forwarding.
[0004] However, traditional route matching uses a linear traversal approach, which requires matching all routing rules one by one. When the number of routes reaches hundreds or even more, the matching time increases significantly, resulting in low gateway route matching efficiency. Therefore, a solution is needed to address the low efficiency of gateway route matching. Summary of the Invention
[0005] Therefore, it is necessary to provide a gateway routing matching method, apparatus, computer device, computer-readable storage medium, and computer program product that can solve the problem of low gateway routing matching efficiency, in order to address the aforementioned technical issues.
[0006] Firstly, this application provides a gateway route matching method, including:
[0007] Obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping the multiple routing rules according to the grouping key values determined by the business dimension;
[0008] In response to a pending business request, a route prefix is extracted from the request path of the pending business request, and a target query key is constructed based on the route prefix;
[0009] If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from the multiple routing rule groups based on the target group key value;
[0010] The target route matching the pending service request is determined from the target routing rule group.
[0011] In one embodiment, obtaining a preset set of multiple routing rule groups includes:
[0012] Obtain all routing rules, and for each of the routing rules, extract the routing type and service line identifier from each routing rule according to the business dimension;
[0013] Based on the route type and service line identifier, a group key value is generated, and route rules belonging to the same group key value are aggregated into the same group to obtain multiple route rule groups.
[0014] In one embodiment, the method further includes:
[0015] If there is no target group key value in the preset cache that matches the target query key, then a full route match is performed from the targeted routing rules according to the request path to determine the matching route;
[0016] Extract the route type and service line identifier of the matched route to generate a group key value;
[0017] A query key is generated based on the route prefix of the request path. The query key and the group key value are stored in the preset cache so that when the same pending business request occurs repeatedly, the step of "if there is a target group key value in the preset cache that matches the query key" is executed to obtain the matching target route.
[0018] In one embodiment, the method further includes:
[0019] Obtain the performance monitoring data corresponding to each of the routing rule groups;
[0020] If the target indicator value in the performance monitoring data is greater than the preset indicator threshold, the group key value update is triggered, and a corresponding group key value update strategy is generated.
[0021] The group key value is updated according to the group key value update strategy so that the matching level of the updated group key value is greater than the matching level of the group key value.
[0022] In one embodiment, the method further includes:
[0023] If a new business line is detected in a business scenario, the new business line identifier of the new business line is obtained;
[0024] Based on the routing type and the new service line identifier in the routing rules of the newly added service line, a corresponding new group key value is generated, and the routing rules of the newly added service line are grouped according to the new group key value.
[0025] In one embodiment, the method further includes:
[0026] In response to an update instruction for a target routing rule, the home routing rule group to which the target routing rule belongs is determined from the plurality of routing rule groups;
[0027] According to the update routing rules carried by the update instruction, the target routing rule in the home routing rule group is hot-updated.
[0028] Secondly, this application also provides a gateway route matching device, comprising:
[0029] The grouping module is used to obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping key values based on business dimensions for the multiple routing rules.
[0030] The request processing module is used to respond to pending business requests, extract route prefixes from the request path of the pending business requests, and construct target query keys based on the route prefixes;
[0031] The route matching module is used to determine a matching target route rule group from multiple route rule groups based on the target group key value if a target group key value matching the query key exists in the preset cache; and to determine a target route matching the pending service request from the target route rule group.
[0032] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0033] Obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping the multiple routing rules according to the grouping key values determined by the business dimension;
[0034] In response to a pending business request, a route prefix is extracted from the request path of the pending business request, and a target query key is constructed based on the route prefix;
[0035] If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from the multiple routing rule groups based on the target group key value;
[0036] The target route matching the pending service request is determined from the target routing rule group.
[0037] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0038] Obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping the multiple routing rules according to the grouping key values determined by the business dimension;
[0039] In response to a pending business request, a route prefix is extracted from the request path of the pending business request, and a target query key is constructed based on the route prefix;
[0040] If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from the multiple routing rule groups based on the target group key value;
[0041] The target route matching the pending service request is determined from the target routing rule group.
[0042] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0043] Obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping the multiple routing rules according to the grouping key values determined by the business dimension;
[0044] In response to a pending business request, a route prefix is extracted from the request path of the pending business request, and a target query key is constructed based on the route prefix;
[0045] If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from the multiple routing rule groups based on the target group key value;
[0046] The target route matching the pending service request is determined from the target routing rule group.
[0047] The aforementioned gateway route matching method, apparatus, computer equipment, computer-readable storage medium, and computer program product group routing rules according to business dimensions, generate grouping key values, group multiple routing rules according to the grouping key values to obtain multiple routing rule groups, and extract route prefixes from the request path of the pending business request in response to the pending business request, constructing a target query key based on the route prefixes; if a target grouping key value matching the query key exists in the preset cache, the matching target routing rule group is determined from the multiple routing rule groups based on the target grouping key value; and the target routing rule group is determined from the target routing rule group. The system determines the target route to match the pending business requests. By aggregating routing rules into logical units according to business dimensions and establishing a searchable index relationship between group key values and query keys, combined with the low-latency key-value retrieval capability provided by the preset cache, the original linear matching process that required traversing all rules is transformed into a two-level matching mechanism that first matches groups and then matches specific routes within groups. By using a grouping strategy to replace linear traversal, the matching range is significantly reduced, the matching time is shortened, and invalid matches are reduced. Especially for high-concurrency scenarios, it can solve the problem of route matching becoming a performance bottleneck, affecting the overall throughput and response latency of the gateway, and reducing system availability. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 This is a flowchart illustrating a gateway route matching method in one embodiment;
[0050] Figure 2 This is a flowchart illustrating a routing rule grouping method in one embodiment;
[0051] Figure 3 This is a schematic diagram illustrating the grouping effect of routing rules in one embodiment;
[0052] Figure 4 This is a flowchart illustrating the gateway route matching method in another embodiment;
[0053] Figure 5 This is a structural block diagram of a gateway routing matching device in one embodiment;
[0054] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0056] Traditional route matching uses a linear traversal approach, requiring the matching of all routing rules one by one. When the number of routes reaches 100 or more, the matching time increases significantly, potentially exceeding 2ms for a single match. This method results in low route matching efficiency. In scenarios with multiple business lines and multiple route types (e.g., mixed APP (Application) / Web / internal services), the traditional route matching method still requires traversing the entire routing table for different types of requests, leading to a large number of invalid matches. Therefore, a method to improve the efficiency of gateway route matching is needed.
[0057] In one embodiment, such as Figure 1 As shown, a gateway route matching method is provided. This embodiment illustrates the method applied to a terminal. It is understood that this method can also be applied to a server, and further to a system including both a terminal and a server, and is implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0058] Step 102: Obtain multiple preset routing rule groups. The routing rule group is determined by grouping multiple routing rules according to the grouping key value determined by the business dimension.
[0059] The routing rule groups can be determined during the system initialization phase by classifying and aggregating registered routing rules according to preset business dimensions. Grouping multiple routing rules by determining grouping keys based on business dimensions can involve analyzing the business attributes of the routing rules, extracting common features as the grouping basis, generating grouping keys, and aggregating the rules to form routing rule groups. For example, routing rule groups can include, but are not limited to, grouping by service module. For instance, if an e-commerce platform's Portal gateway connects to 10 business lines (orders, users, products, payment, logistics, marketing, customer service, data, search, recommendation, etc.), and each business line contains two routing types (APP and Web), totaling 100 routing rules, then the corresponding routing rules can be grouped based on different business lines. This allows for matching groups first during route matching, and then matching specific routes within groups, optimizing the time complexity from O(n) to O(1+n / m), where m is the number of groups and n is the total number of routes.
[0060] In a group key-value pair, the group key can be, but is not limited to, a route type, and the corresponding value can be, but is not limited to, a business line identifier. Route types can include application routes (APP routes), web routes, and internal service routes, etc. Each group key-value pair has a corresponding route list. The route list includes at least one routing rule, which includes a route and its corresponding route predicate. Routes can include different routes based on business scenarios, such as user routes, order routes, and login routes. A route predicate is a conditional expression used in network routing or API gateways to dynamically determine whether a request matches a specific routing rule. It evaluates various request attributes (such as path, request headers, parameters, etc.) to determine which target service or processing path the request should be forwarded to.
[0061] Step 104: In response to the pending business request, extract the route prefix from the request path of the pending business request, and construct the target query key based on the route prefix.
[0062] The pending business request can be an HTTP request. The target query key is used as input for cache lookup, enabling fast indexing and location of the target routing rule group.
[0063] For example, a route prefix is extracted from the request path of the business request to be processed, and a target query key is constructed based on the route prefix. This can be achieved by parsing the request URL path, extracting its first segment or prefix, and converting it into a standardized format as the query key. Furthermore, this operation can be implemented as described above, thereby generating a unified key-value pair that can be used for cache lookup, ensuring compatibility with the preset grouping key-value pair format.
[0064] Step 106: If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from multiple routing rule groups based on the target group key value.
[0065] The preset cache can be a high-speed in-memory data structure that stores the mapping relationship between group key values and corresponding routing rule groups. It can be used to provide low-latency key-value lookup capabilities and accelerate the process of locating routing rule groups. Optionally, the preset cache can load the mapping relationship between group key values and routing rule groups into the memory cache when the system starts up or the routing configuration is updated.
[0066] For example, a lookup operation is performed in the preset cache using the query key. If a match is found, the corresponding route rule group is returned. The lookup operation can be implemented by using a hash table for O(1) level key-value matching, which can skip the full rule scan and directly enter the matching within a specific group, reducing invalid comparisons. Especially in scenarios with multiple business lines and multiple route types (APP / Web / internal services), different types of requests still need to traverse the entire route table, resulting in a large number of invalid matches. Therefore, this method can avoid invalid matches across business lines and types.
[0067] Step 108: Determine the target route that matches the pending business request from the target routing rule group.
[0068] Specifically, determining the target route that matches the pending business request within the target routing rule group can be achieved by using regular expressions or exact matching algorithms to match routing rules within the group, determining the target route, and then forwarding the pending business request to the target route.
[0069] Under normal circumstances, traditional methods suffer from matching efficiency issues when dealing with a large number of routes. While improvements to efficiency are typically found in optimizing network parameters (latency, load, protocol efficiency, etc.) or enhancing hardware / algorithm performance, the gateway route matching method described above improves efficiency by grouping numerous routing rules based on business needs. This two-level matching mechanism (first matching groups, then matching specific routes within groups) enhances route matching efficiency while also adapting to business requirements, directly achieving precise matching between business objectives and routing rules, thus transcending the traditional technical framework.
[0070] The aforementioned gateway route matching method groups routing rules according to business dimensions, generates group key values, and groups multiple routing rules according to the group key values to obtain multiple routing rule groups. In response to a pending business request, it extracts the route prefix from the request path of the pending business request and constructs a target query key based on the route prefix. If a target group key value matching the query key exists in the preset cache, it determines the matching target routing rule group from the multiple routing rule groups based on the target group key value. It determines the target route matching the pending business request from the target routing rule group. By aggregating routing rules into logical units according to business dimensions and establishing a searchable index relationship between group key values and query keys, combined with the low-latency key value retrieval capability provided by the preset cache, the original linear matching process requiring traversal of all rules is transformed into a two-level matching mechanism: first matching groups, then matching specific routes within groups. Using a grouping strategy instead of linear traversal significantly reduces the matching range, shortens matching time, and reduces invalid matches. Especially for high-concurrency scenarios, it can solve the problem of route matching becoming a performance bottleneck, affecting the overall throughput and response latency of the gateway, and reducing system availability.
[0071] Understandably, traditional route matching uses a linear traversal approach, which requires matching all route rules one by one. For example, when the number of routes reaches 100 or more, the matching time increases significantly, and a single match may take more than 2ms. Therefore, a grouping strategy is adopted to replace linear traversal, and the route rules are grouped and managed according to business dimensions.
[0072] In one exemplary embodiment, such as Figure 2 As shown, a method for grouping routing rules is provided, including the following steps:
[0073] Step 202: Obtain all routing rules. For each routing rule, extract the route type and business line identifier from each routing rule according to the business dimension.
[0074] Among them, the business line identifier can be a unique identifier that indicates the specific business line or product line to which the routing rule belongs. It can be used as one of the constituent elements of the group key value to realize routing isolation and classification according to business affiliation.
[0075] For example, all routing rules are obtained. For each routing rule, the configuration information of each routing rule is parsed. According to the preset business dimension definition, the routing type and business line identifier fields contained therein are read. The extracted routing type and business line identifier are concatenated or encoded in a fixed order to form a string or hash value in a uniform format as a grouping key value.
[0076] Step 204: Generate a group key value based on the route type and service line identifier, and aggregate route rules belonging to the same group key value into the same group to obtain multiple route rule groups.
[0077] Generating grouped key values can be achieved by generating readable key values through string concatenation, or by encoding combined fields using a hash function to generate compact key values, thereby constructing standardized index identifiers that can be used for routing rule aggregation and cache lookup.
[0078] For example, when the gateway starts, it preprocesses and initializes groups for all routing rules; extracts the route type (APP / Web / Internal) and business line identifier from the routing rules, and generates a group key value "type:business line"groupKey; and aggregates routing rules with the same group key value into the same group, establishing a mapping relationship between the group key value and the route list.
[0079] For example, following the method described above, the routing rules are grouped. The following three groups of routing rules have corresponding group key values of app:mpt, web:mpt, and web:flowmore, respectively. The route list corresponding to app:mpt is as follows:
[0080] app:mpt->
[0081] {
[0082] The user route is userAppRoute, and the corresponding route assertion is / app / mpt / v1 / user / get / ;
[0083] The order route is orderAppRoute, and the corresponding route assertion is / app / mpt / v1 / order / get / ;
[0084] The login route is loginAppRoute, and the corresponding route assertion is / app / mpt / v1 / login / get / ;
[0085] };
[0086] The route list corresponding to web:mpt is as follows:
[0087] web:mpt->
[0088] {
[0089] The user route is userWebRoute, and the corresponding route assertion is / web / mpt / v1 / user / get / ;
[0090] The order route is orderWebRoute, and the corresponding route assertion is / web / mpt / v1 / order / get / ;
[0091] The login route is loginWebRoute, and the corresponding route assertion is / web / mpt / v1 / login / get / ;
[0092] };
[0093] The route list corresponding to web:flowmore is as follows:
[0094] web:flowmore->
[0095] {
[0096] The user route is userWebRoute, and the corresponding route assertion is / web / flowmore / v1 / user / get / ;
[0097] The order route is orderWebRoute, and the corresponding route assertion is / web / flowmore / v1 / order / get / ;
[0098] The login route is loginWebRoute, and the corresponding route assertion is / web / flowmore / v1 / login / get / ;
[0099] };
[0100] In one exemplary embodiment, such as Figure 3 As shown, this is a schematic diagram illustrating the grouping effect of routing rules according to the grouping method. All routing rules are obtained. For each routing rule, the routing type is extracted from each routing rule according to the business dimension, including three major routing types: APP routing, Web routing, and internal routing. Based on this, the routing is further grouped according to the business line identifier to obtain routes belonging to the three major routing types of APP routing, Web routing, and internal routing and belonging to the same business line. For example, the business line includes business line 1, business line 2, business line 3, ..., business line n.
[0101] In the above routing rule grouping method, all routing rules are obtained and the routing type and business line identifier are extracted from them according to the business dimension. Grouping key values are generated based on the routing type and business line identifier, and routing rules belonging to the same grouping key value are aggregated into the same group to obtain multiple routing rule groups. This allows the target group to be quickly located by querying the key when matching requests, which greatly reduces the number of rules that need to be compared, avoids the linear traversal method that requires matching all routing rules one by one, optimizes the time complexity and reduces the matching time.
[0102] During the initialization phase, if the business request to be processed is the first request, the pre-set cache may not contain the group key value corresponding to the business request. However, in actual business scenarios, the request does not necessarily occur only once. Therefore, to address this situation, in an exemplary embodiment, as follows... Figure 4 As shown, another gateway route matching method is provided, which includes the following steps:
[0103] Step 402: Obtain multiple preset routing rule groups. The routing rule group is determined by grouping multiple routing rules according to the grouping key value determined by the business dimension.
[0104] Step 404: In response to the pending business request, if there is no target group key value in the preset cache that matches the target query key, then perform a full route matching based on the request path and the corresponding routing rules to determine the matching route.
[0105] If the target group key value that matches the target query key does not exist in the preset cache, a full route match is performed based on the request path and the corresponding routing rules to determine the matching route. This can be achieved by iterating through all registered routing rules and performing a match on each rule according to the path when a cache miss occurs, until a matching route is found. Furthermore, this operation can be implemented, but is not limited to, by using regular expressions to compare the request path with each routing rule.
[0106] Step 406: Extract the route type and service line identifier of the matching route and generate group key values.
[0107] Step 408: Generate a query key based on the route prefix of the request path, and store the query key and group key value in a preset cache so that when the same pending business request occurs repeatedly, the step of if a target group key value matching the query key exists in the preset cache is executed to obtain the matching target route.
[0108] The process involves generating a query key based on the routing prefix of the request path, and storing the query key and group key-value pair in a preset cache. This can be achieved by extracting the prefix from the current request path, standardizing it into a query key, and then mapping this key to the generated group key-value pair and persisting it to the preset cache. Alternatively, the routing prefix of the request path can be hashed to generate a hash index, which is then used as the query key. For example, if the pending business request is / web / mpt / v1 / user / get / 1, the routing prefix of the pending business request is extracted, specifically the first four characters: / web / mpt / v1 / user. This / web / mpt / v1 / user is then hashed to generate a hash index, which is used as the query key. Alternatively, / web / mpt / v1 / user can be directly used as the query key, and both / web / mpt / v1 / user and the corresponding group key-value pair web:mpt are stored as a whole in the cache.
[0109] Furthermore, by establishing an index of path prefixes, the prefix matching algorithm can quickly locate groups when a request arrives, reducing the matching time from 2ms to 0.2ms, a 10-fold performance improvement, and significantly reducing CPU consumption in high-concurrency scenarios.
[0110] For example, based on Figure 2 In the corresponding embodiment, when the first request / web / mpt / v1 / user / get / 1 arrives, it doesn't exist in the cache. Therefore, a full route is performed. After full route matching, the route "userWebRoute" is matched, and the corresponding route group key "web:mpt" is found. / web / mpt / v1 / user and web:mpt are added as a whole to the cache. For repeated requests, i.e., when / web / mpt / v1 / user / get / 1 arrives a second time, the first four characters of the request path are extracted. / web / mpt / v1 / user is matched against the corresponding group key "web:mpt" in the cache. The route rule group corresponding to web:mpt is found, and then matching is performed within that group, matching "userWebRoute". It should be noted that when configuring the route rules, the first four characters of the request path cannot be repeated across different route types and business lines. It can be understood that if no match is found, a full route matching is used. Furthermore, it can also record matching time and hit rate metrics for performance monitoring and grouping strategy optimization, i.e., updating grouping key values.
[0111] The aforementioned gateway route matching method performs full route matching to determine the matching route if no target group key value matching the target query key exists in the preset cache. It then extracts the route type and business line identifier from the matching route to generate a group key value, and generates a query key based on the request path prefix. These two keys are then combined and written into the preset cache. This allows the same pending business request to be directly mapped to the corresponding route rule group for matching when it occurs repeatedly. This transforms the original linear matching process, which required traversing all rules, into a two-level matching mechanism: first matching groups, then matching specific routes within those groups. By replacing linear traversal with a grouping strategy, the matching range is significantly reduced, matching time is shortened, and invalid matches are decreased. Especially in high-concurrency scenarios, this method can solve the problem of route matching becoming a performance bottleneck, affecting the overall gateway throughput and response latency, and reducing system availability.
[0112] As business expands and routing rules continue to increase, matching performance declines linearly, lacking scalability. In an exemplary embodiment, the above-described gateway routing matching method further includes the following steps:
[0113] Obtain performance monitoring data corresponding to each routing rule group; if the target indicator value in the performance monitoring data is greater than the preset indicator threshold, trigger group key value update and generate the corresponding group key value update strategy; update the group key value according to the group key value update strategy so that the matching level of the updated group key value is greater than the matching level of the group key value.
[0114] The performance monitoring data can be a set of quantitative indicators reflecting the runtime matching performance of each routing rule group. It can be used to evaluate the effectiveness of the current grouping structure and provide a basis for dynamic adjustments. Performance monitoring data can include, but is not limited to, one or more of the following: number of routes, matching time, and hit rate. Obtaining the performance monitoring data for each routing rule group can be achieved by periodically pulling performance data from each group using asynchronous polling or by receiving performance reporting messages through an event-driven mechanism.
[0115] Preset threshold values can be pre-defined performance indicator cutoff values used to compare with target indicator values to determine group status, and can serve as triggering benchmarks for group key-value updates. Group key-value update strategies can define how to reconstruct existing group key-value pairs to achieve finer-grained partitioning, and can be used to guide the system to split or reorganize overloaded routing rule groups to optimize matching efficiency.
[0116] For example, if the target metric value in the performance monitoring data exceeds a preset metric threshold, a group key-value update is triggered, generating a corresponding group key-value update strategy. This can be achieved by comparing the collected target metric value with the preset metric threshold; if the threshold is exceeded, the strategy generation process is initiated. Optionally, the group key-value update strategy can be implemented by a rule engine to determine and generate a strategy, or by using a machine learning model to predict trends and generate a tiered response strategy. This enables adaptive feedback control based on actual load conditions, avoiding manual intervention. For instance, a group splitting strategy can be automatically triggered based on monitoring data; when the number of routes in a single group exceeds the corresponding metric threshold, it can be further subdivided according to sub-business dimensions.
[0117] In the above embodiments, by obtaining the performance monitoring data corresponding to each routing rule group, the group splitting strategy is automatically triggered based on the performance monitoring data. When the number of routes in a single group exceeds the threshold, it is further subdivided according to the sub-service dimension to achieve further subdivision of the original group, thereby avoiding the continuous increase of routing rules and the linear decline in matching performance.
[0118] In an exemplary embodiment, the above-mentioned gateway route matching can also achieve the following when a new business line is detected in the business scenario: obtaining the new business line identifier of the new business line; generating a corresponding new group key value according to the route type and the new business line identifier in the routing rules of the new business line; and grouping the routing rules of the new business line according to the new group key value.
[0119] For example, when a new business line is detected in a business scenario, the identifier of the new business line is obtained. Based on the new business line identifier, corresponding APP and Web routing groups are automatically created, and the routing rules for the new business line are grouped according to the new group key value. For instance, when a "Membership Business Line" is added, two groups, "APP:Membership Business" and "Web:Membership Business," are automatically created without affecting the matching performance of the existing 20 groups, demonstrating the system's good horizontal scalability. In other words, this approach allows for the creation of new groups when a new business line is added, without impacting the matching performance of existing groups.
[0120] In an exemplary embodiment, the gateway route matching described above can also respond to an update instruction for a target route rule, determine the home route rule group to which the target route rule belongs from multiple route rule groups, and perform a hot update on the target route rule in the home route rule group according to the update route rule carried by the update instruction. This method supports hot updates of route rules at the group level without restarting the gateway service, which can avoid service interruption caused by restarting, thereby ensuring the high availability and agility of the system.
[0121] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0122] Based on the same inventive concept, this application also provides a gateway route matching device for implementing the gateway route matching method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more gateway route matching device embodiments provided below can be found in the limitations of the gateway route matching method described above, and will not be repeated here.
[0123] In one exemplary embodiment, such as Figure 5 As shown, a gateway route matching device is provided, including: a grouping module 502, a request processing module 504, and a route matching module 506, wherein:
[0124] The grouping module 502 is used to obtain multiple preset routing rule groups. The routing rule group is determined by grouping the multiple routing rules according to the grouping key value determined by the business dimension.
[0125] The request processing module 504 is used to respond to pending business requests by extracting route prefixes from the request path of the pending business requests and constructing target query keys based on the route prefixes.
[0126] The route matching module 506 is used to determine the matching target route rule group from multiple route rule groups based on the target group key value if a target group key value matching the query key exists in the preset cache; and to determine the target route matching the business request to be processed from the target route rule group.
[0127] The aforementioned gateway route matching device groups routing rules according to business dimensions, generates group key values, and groups multiple routing rules according to the group key values to obtain multiple routing rule groups. In response to a pending business request, it extracts the route prefix from the request path of the pending business request and constructs a target query key based on the route prefix. If a target group key value matching the query key exists in the preset cache, it determines the matching target routing rule group from the multiple routing rule groups based on the target group key value. It then determines the target route matching the pending business request from the target routing rule group. By aggregating routing rules into logical units according to business dimensions and establishing a searchable index relationship between group key values and query keys, combined with the low-latency key value retrieval capability provided by the preset cache, the original linear matching process requiring traversal of all rules is transformed into a two-level matching mechanism: first matching groups, then matching specific routes within groups. Using a grouping strategy instead of linear traversal significantly reduces the matching range, shortens matching time, and reduces invalid matches. Especially in high-concurrency scenarios, it can solve the problem of route matching becoming a performance bottleneck, affecting the overall throughput and response latency of the gateway, and reducing system availability.
[0128] In an exemplary embodiment, the grouping module 502 is used to obtain all routing rules, and for each routing rule among all routing rules, extract the routing type and service line identifier from each routing rule according to the service dimension;
[0129] Generate group key values based on route type and service line identifier, and aggregate route rules belonging to the same group key value into the same group to obtain multiple route rule groups.
[0130] In an exemplary embodiment, the route matching module 506 is configured to, if no target group key value matching the target query key exists in the preset cache, perform full route matching based on the target routing rules according to the request path to determine the matching route; extract the route type and business line identifier of the matching route to generate a group key value; generate a query key based on the route prefix of the request path; and store the query key and group key value in the preset cache so that when the same pending business request appears repeatedly, a matching target route is obtained.
[0131] In an exemplary embodiment, the gateway route matching device further includes an update module, which is used to obtain performance monitoring data corresponding to each routing rule group; if the target indicator value in the performance monitoring data is greater than a preset indicator threshold, then triggering a group key value update to generate a corresponding group key value update strategy; updating the group key value according to the group key value update strategy so that the matching level of the updated group key value is greater than the matching level of the group key value.
[0132] In an exemplary embodiment, the grouping module 502 is used to obtain the new business line identifier of the newly added business line when a new business line is detected in the business scenario.
[0133] Generate corresponding new group key values based on the routing type and new service line identifier in the routing rules of the new service line, and group the routing rules of the new service line according to the new group key values.
[0134] In an exemplary embodiment, the update module is configured to include, in response to an update instruction for a target routing rule, determining from a plurality of routing rule groups the home routing rule group to which the target routing rule belongs; and performing a hot update on the target routing rule in the home routing rule group according to the update routing rule carried by the update instruction.
[0135] Each module in the aforementioned gateway routing matching device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.
[0136] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When executed by the processor, the computer program implements a gateway routing matching method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0137] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0138] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0139] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0140] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0141] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0142] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0143] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0144] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A gateway route matching method, characterized in that, The method includes: Obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping the multiple routing rules according to the grouping key values determined by the business dimension; In response to a pending business request, a route prefix is extracted from the request path of the pending business request, and a target query key is constructed based on the route prefix; If a target group key value matching the query key exists in the preset cache, then the matching target routing rule group is determined from the multiple routing rule groups based on the target group key value; The target route matching the pending service request is determined from the target routing rule group.
2. The method according to claim 1, characterized in that, The process of obtaining multiple preset routing rule groups includes: Obtain all routing rules, and for each of the routing rules, extract the routing type and business line identifier from each routing rule according to the business dimension; Based on the route type and service line identifier, a group key value is generated, and route rules belonging to the same group key value are aggregated into the same group to obtain multiple route rule groups.
3. The method according to claim 1, characterized in that, The method further includes: If there is no target group key value in the preset cache that matches the target query key, then a full route match is performed from the targeted routing rules according to the request path to determine the matching route; Extract the route type and service line identifier of the matched route to generate a group key value; A query key is generated based on the route prefix of the request path. The query key and the group key value are stored in the preset cache so that when the same pending business request occurs repeatedly, the step of "if there is a target group key value in the preset cache that matches the query key" is executed to obtain the matching target route.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: Obtain the performance monitoring data corresponding to each of the routing rule groups; If the target indicator value in the performance monitoring data is greater than the preset indicator threshold, the group key value update is triggered, and a corresponding group key value update strategy is generated. The group key value is updated according to the group key value update strategy so that the matching level of the updated group key value is greater than the matching level of the group key value.
5. The method according to claim 4, characterized in that, The method further includes: If a new business line is detected in a business scenario, the new business line identifier of the new business line is obtained; Based on the routing type and the new service line identifier in the routing rules of the newly added service line, a corresponding new group key value is generated, and the routing rules of the newly added service line are grouped according to the new group key value.
6. The method according to claim 5, characterized in that, The method further includes: In response to an update instruction for a target routing rule, the home routing rule group to which the target routing rule belongs is determined from the plurality of routing rule groups; According to the update routing rules carried by the update instruction, the target routing rule in the home routing rule group is hot-updated.
7. A gateway route matching device, characterized in that, The device includes: The grouping module is used to obtain multiple preset routing rule groups, wherein the routing rule groups are determined by grouping key values based on business dimensions for the multiple routing rules. The request processing module is used to respond to pending business requests, extract route prefixes from the request path of the pending business requests, and construct target query keys based on the route prefixes; The route matching module is used to determine a matching target route rule group from multiple route rule groups based on the target group key value if a target group key value matching the query key exists in the preset cache; and to determine a target route matching the pending service request from the target route rule group.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.