Method, apparatus, computer device and storage medium for automatically constructing a route by a gateway

By configuring common routing and custom global filters in the gateway program, the routing in the microservice architecture is automatically built, which solves the problem of artificial configuration and restarting services in the existing technology, improves gateway processing efficiency and reduces labor costs.

CN116032822BActive Publication Date: 2025-07-04SHENZHEN WANRUI INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211609349.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-14
Publication Date
2025-07-04
Estimated Expiration
2042-12-14

AI Technical Summary

Technical Problem

In the microservice architecture, gateway routing configuration requires manual manual addition and restart of services, resulting in large maintenance workloads and affecting normal operation.

Method used

By configuring common routes and custom global filters in the gateway program, new routes are automatically built, avoiding manual configuration and service restarts, and using global filters to automatically match and build routes according to path configuration rules.

Benefits of technology

It realizes automatic gateway construction routes without shutting down services, improving the efficiency of handling client requests and reducing labor costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116032822B_ABST
    Figure CN116032822B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, computer equipment and storage medium for automatically constructing routes by a gateway; the method includes: a user configures a general route in the gateway program; edits the service network switch; customizes a global filter for automatically constructing a new route according to the general route; restarts the gateway program; the gateway program reads the configuration of the general route and constructs the general route; obtains the client request and the general route through the service network switch; matches the general route according to the client request and constructs a new route, and places the new route in the service network switch; forwards the client request to the microservice according to the new route; the microservice processes the client request. The present invention can avoid the need for manual addition of route configuration and restarting of the gateway service when a new microservice is requested, realizes automatic route construction by the gateway without restarting the gateway service, improves the efficiency of processing client requests, and reduces labor costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of gateway routing configuration, and more specifically to a method, device, computer device and storage medium for automatically constructing routes by a gateway. Background Art

[0002] With the development of Internet technology, the past monolithic application architecture has gradually transitioned to a microservices architecture. The microservices architecture is a design style that splits a large single application program and service into several microservices, and the microservices communicate with each other through the HTTP protocol (HyperText Transfer Protocol). The gateway provides a unified entry for the microservices cloud platform. In addition, the gateway can also undertake non-business functions such as authentication and authorization, access control, routing, load balancing, caching, logging, flow limiting and quota, conversion, filtering, fusing, registration, service orchestration, API (Application Programming Interface) management, monitoring, statistical analysis, and so on.

[0003] In the Java field, the common implementation principle of a microservices gateway is as follows: when starting the service, the routing configuration in the configuration file is read into the memory and a routing object is constructed. When an external request arrives, the routing object is matched by the path. If the match is successful, the downstream microservice is called; if the match is unsuccessful, it fails. Every time a new microservice is added, a new routing configuration needs to be added to the configuration file and then the service is restarted. This method requires manual addition of configurations and stopping and starting of the service, increasing the maintenance workload and affecting the normal operation of the service.

[0004] Therefore, it is necessary to design a new method to realize automatic route construction by the gateway without stopping and starting the gateway service, improve the efficiency of the gateway in processing and forwarding client requests, and reduce labor costs. Summary of the Invention

[0005] The purpose of the present invention is to overcome the defects of the prior art, and provide a method, device, computer device and storage medium for automatically constructing routes by a gateway.

[0006] To achieve the above purpose, the present invention adopts the following technical solutions:

[0007] In the first aspect, this embodiment provides a method for automatically constructing routes by a gateway, including:

[0008] A user configures a general route in the configuration file of the gateway program;

[0009] The user edits a service network switch in the gateway program, and the service network switch is used to obtain the client request and the general route;

[0010] The user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route;

[0011] The user restarts the gateway program;

[0012] The gateway program reads the configuration of the general route and constructs the general route;

[0013] The gateway program obtains the client request and the general route through the service network exchanger;

[0014] The gateway program matches the general route according to the client request, constructs a new route, and places the new route in the service network exchanger;

[0015] The gateway program forwards the client request to the microservice according to the new route.

[0016] Its further technical solution is that the user configures a general route in the configuration file of the gateway program, including:

[0017] Configure the id of the general route as the unique identifier of the route;

[0018] Configure the name of the general route as the route name;

[0019] Configure the uri of the general route as the request path;

[0020] Configure the assertion of the general route as the path configuration rule, and match the general route according to the prefix path of the request path;

[0021] Configure the route filter of the general route as the filter for rewriting the request path.

[0022] Its further technical solution is that the user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route, including:

[0023] The user edits the global filter interface in the gateway program to define the execution behavior of the global filter;

[0024] The user edits the sorting interface in the gateway program to define the execution order of the global filter.

[0025] Its further technical solution is that the execution behavior of the global filter includes:

[0026] The global filter obtains the request path from the general route, and obtains the second-level path data as the microservice name according to the path configuration rule;

[0027] The global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule;

[0028] The global filter places the new route into the service network switch and then into the filter chain.

[0029] A further technical solution thereof is that: the user edits a sorting interface in the gateway program to define the execution order of the global filter, including:

[0030] Define the return value of the getOrder() method in the sorting interface to be a value less than 10100. The smaller the value, the higher the execution priority of the global filter.

[0031] A further technical solution thereof is that: the gateway program matches a general route according to the client request, constructs a new route, and places the new route into the service network switch, including:

[0032] The gateway program places the client request into a filter chain composed of a route filter and a global filter;

[0033] The global filter obtains the request path from the general route, and according to the path configuration rule, obtains the second-level path data as the microservice name;

[0034] The route filter rewrites the request path;

[0035] The global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule;

[0036] The global filter places the new route into the service network switch and then into the filter chain.

[0037] In a second aspect, this embodiment provides a device for automatically constructing a route by a gateway, which executes the above-mentioned method, including: a configuration unit, an editing unit, a customizing unit, a restart unit, a reading and constructing unit, an obtaining unit, a matching and constructing unit, and a forwarding unit;

[0038] The configuration unit is used for the user to configure a general route in the configuration file of the gateway program;

[0039] The editing unit is used for the user to edit the service network switch in the gateway program, and the service network switch is used to obtain the client request and the general route;

[0040] The customizing unit is used for the user to customize a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route;

[0041] The restart unit is used for the user to restart the gateway program;

[0042] The reading and constructing unit is used for the gateway program to read the configuration of the general route and construct the general route;

[0043] The obtaining unit is used for the gateway program to obtain client requests and general routes through the service network switch;

[0044] The matching and constructing unit is used for the gateway program to match general routes according to client requests, construct new routes, and place the new routes into the service network switch;

[0045] The forwarding unit is used for the gateway program to forward client requests to microservices according to the new routes.

[0046] A further technical solution thereof is that the matching and constructing unit includes: a request placing module, an obtaining module, a rewriting module, a constructing module, and a route placing module;

[0047] The request placing module is used for the gateway program to place client requests into a filter chain composed of a route filter and a global filter;

[0048] The obtaining module is used for the global filter to obtain a request path from the general route, and according to path configuration rules, obtain second-level path data as the microservice name;

[0049] The rewriting module is used for the route filter to rewrite the request path;

[0050] The constructing module is used for the global filter to construct a new uri object, use the new uri as a parameter, and construct a new route according to path configuration rules;

[0051] The route placing module is used for the global filter to place the new route into the service network switch and then into the filter chain.

[0052] In a third aspect, this embodiment provides a computer device, which includes a memory and a processor. A computer program is stored on the memory, and when the processor executes the computer program, the method for the gateway to automatically construct routes as described above is implemented.

[0053] In a fourth aspect, this embodiment provides a storage medium, which stores a computer program. The computer program includes program instructions, and when the program instructions are executed by a processor, the method for the gateway to automatically construct routes as described above can be implemented.

[0054] The beneficial effects of the present invention compared with the prior art are as follows: The global filter is defined to automatically configure routes according to the path configuration rules in the general route. When processing client requests with the filter chain, the routes can be directly and automatically configured, which can avoid the need to manually add route configurations and stop / start the gateway service when a new microservice is added to the request. It realizes the automatic construction of routes by the gateway without stopping / starting the gateway service, improves the efficiency of the gateway in processing and forwarding client requests, and reduces the labor cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0056] Figure 1 It is a schematic diagram of the application scenario of the method for automatically constructing routes by the gateway provided in the embodiment of the present invention;

[0057] Figure 2 It is a schematic flow diagram of the method for automatically constructing routes by the gateway provided in the embodiment of the present invention;

[0058] Figure 3 It is a schematic diagram of the sub - process of the method for automatically constructing routes by the gateway provided in the embodiment of the present invention Figure 1 ;

[0059] Figure 4 It is a schematic diagram of the sub - process of the method for automatically constructing routes by the gateway provided in the embodiment of the present invention Figure 2 ;

[0060] Figure 5 It is a schematic block diagram of the device for automatically constructing routes by the gateway provided in the embodiment of the present invention Figure 1 ;

[0061] Figure 6 It is a schematic block diagram of the device for automatically constructing routes by the gateway provided in the embodiment of the present invention Figure 2 ;

[0062] Figure 7 It is a schematic block diagram of the computer device provided in the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0063] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts belong to the scope of protection of the present invention.

[0064] It should be understood that when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, wholes, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0065] It should also be understood that the terms used in this specification of the present invention are for the purpose of describing particular embodiments only and are not intended to limit the present invention. As used in this specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an", and "the" are intended to include the plural forms.

[0066] It should be further understood that the term " / and / " used in this specification of the present invention and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0067] Please refer to Figure 1 and Figure 2 , Figure 1 is a schematic diagram of the application scenario of the method for the gateway to automatically construct a route provided by an embodiment of the present invention. The method for the gateway to automatically construct a route is applied to the gateway 10. The client 20 requests to add a microservice. The gateway 10 matches a general route according to the request and automatically generates a new route, and then forwards the request to the microservice 30 according to the new route.

[0068] Figure 2 is a schematic flowchart of the method for the gateway to automatically construct a route provided by an embodiment of the present invention. As shown in the figure, the method includes the following steps.

[0069] S110. The user configures a general route in the configuration file of the gateway program.

[0070] In one embodiment, please refer to Figure 3 , the above step S110 may include steps S111 - S115.

[0071] S111. Configure the id of the general route as the unique route identifier.

[0072] S112. Configure the name of the general route as the route name.

[0073] S113. Configure the uri of the general route as the request path.

[0074] Specifically, the form of the request path is / prefix path / microservice name / interface address, where the prefix path can be any value.

[0075] S114. Configure the assertion of the general route as a path configuration rule, and match the general route according to the prefix path of the request path.

[0076] Specifically, the path configuration rule can be set so that the general route can be matched only when the prefix path is a certain specific value.

[0077] S115. Configure the route filter of the general route as a filter for rewriting the request path.

[0078] Specifically, when the route filter rewrites the request path, it removes the " / " and the prefix path.

[0079] S120. The user edits the service network switch in the gateway program, and the service network switch is used to obtain the client request and the general route.

[0080] The service network switch is a contract for HTTP (HyperText Transfer Protocol) request-response interaction and can store important request attributes. In one embodiment, the service network switch stores the client request and the general route. Subsequently, when using the filter chain composed of the route filter and the global filter to process the request, it is necessary to obtain the client request and the general route from it, and at the same time, the new route also needs to be placed in the service network switch after constructing the new route.

[0081] S130. The user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route.

[0082] The global filter does not need to be configured through a configuration file and acts on all routes. Customizing the global filter means defining the execution behavior and execution priority of the global filter;

[0083] In one embodiment, the user defines the execution behavior of the global filter by editing the global filter interface. The execution behavior of the global filter specifically includes: the global filter obtains the request path from the general route and obtains the second-level path data as the microservice name according to the path configuration rule; the global filter constructs a new uri object and uses the new uri as a parameter to construct a new route according to the path configuration rule; the global filter places the new route in the service network switch and then in the filter chain;

[0084] In another embodiment, the user edits the sorting interface in the gateway program to define the execution order of the global filter, including: defining the return value of the getOrder() method in the sorting interface as a value less than 10100, and the smaller the value, the higher the execution priority of the global filter.

[0085] S140. The user restarts the gateway program.

[0086] S150. The gateway program reads the configuration of the general route and constructs the general route.

[0087] Specifically, it reads the id, name, uri, assertion, and route filter in the general route configuration. Among them, id is the unique identifier of the route; name is the route name; uri is the request path; the assertion is the path configuration rule, which matches the general route according to the prefix path of the request path; the route filter is the filter for rewriting the request path. The form of the request path is / prefix path / microservice name / interface address, where the prefix path can be any value. The assertion can be set to match the general route only when the prefix path is a specific value. When the route filter rewrites the request path, it removes the " / " and the prefix path. A corresponding general route object is constructed according to this configuration.

[0088] S160. The gateway program obtains the client request and the general route through the service network exchanger.

[0089] S170. The gateway program matches the general route according to the client request, constructs a new route, and places the new route into the service network exchanger.

[0090] In one embodiment, please refer to Figure 4 , the above step S170 may include steps S171 - S175.

[0091] S171. The gateway program places the client request into the filter chain composed of the route filter and the global filter.

[0092] S172. The global filter obtains the request path from the general route and obtains the second - level path data as the microservice name according to the path configuration rule.

[0093] S173. The route filter rewrites the request path.

[0094] In one embodiment, the form of the request path is / prefix path / microservice name / interface address, where the prefix path can be any value; when the route filter rewrites the request path, it removes the " / " and the prefix path.

[0095] S174. The global filter constructs a new uri object, uses the new uri as a parameter, and constructs a new route according to the path configuration rule.

[0096] In one embodiment, the form of the new uri object is also / prefix path / microservice name / interface address, where the prefix path can be any value.

[0097] S175. The global filter places the new route into the service network exchanger and then into the filter chain.

[0098] S180. The gateway program forwards the client request to the microservice according to the new route.

[0099] When the gateway receives the client request subsequently, it is not necessary to execute the steps of S110 - S150 anymore. The gateway program can automatically construct a new route and forward the client request to the microservice, and there is no need to stop and start the gateway again, which improves the efficiency of the gateway in processing and forwarding client requests and reduces the labor cost.

[0100] Figure 5 It is a schematic block diagram of the device for the gateway to automatically construct a route provided by an embodiment of the present invention. Figure 1 As Figure 5 shown, corresponding to the above method for the gateway to automatically construct a route, the present invention also provides a device 300 for the gateway to automatically construct a route. The device 300 for the gateway to automatically construct a route includes units for executing the above method for the gateway to automatically construct a route. The device can be configured in terminals such as desktop computers, tablet computers, laptop computers, etc.

[0101] Specifically, please refer to Figure 5 , the device 300 for the gateway to automatically construct a route includes a configuration unit 301, an editing unit 302, a customization unit 303, a restart unit 304, a reading and construction unit 305, an obtaining unit 306, a matching and construction unit 307, and a forwarding unit 308;

[0102] The configuration unit 301 is used for the user to configure a general route in the configuration file of the gateway program;

[0103] The editing unit 302 is used for the user to edit the service network switch in the gateway program, and the service network switch is used to obtain the client request and the general route;

[0104] The customization unit 303 is used for the user to customize a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route;

[0105] The restart unit 304 is used for the user to restart the gateway program;

[0106] The reading and construction unit 305 is used for the gateway program to read the configuration of the general route and construct the general route;

[0107] The obtaining unit 306 is used for the gateway program to obtain the client request and the general route through the service network switch;

[0108] The matching and construction unit 307 is used for the gateway program to match the general route according to the client request, construct a new route, and place the new route in the service network switch;

[0109] The forwarding unit 308 is used for the gateway program to forward the client request to the microservice according to the new route.

[0110] In one embodiment, the configuration unit 301 is specifically used for:

[0111] Configure the id of the general route as the unique route identifier; configure the name of the general route as the route name; configure the uri of the general route as the request path; configure the assertion of the general route as the path configuration rule to match the general route according to the prefix path of the request path; configure the route filter of the general route as the filter for rewriting the request path.

[0112] In one embodiment, the customization unit 303 is specifically used for:

[0113] The user edits the global filter interface in the gateway program to define the execution behavior of the global filter; the user edits the sorting interface in the gateway program to define the execution order of the global filter.

[0114] In one embodiment, the matching and building unit 307 is specifically used for: the gateway program puts the client request into the filter chain composed of the route filter and the global filter; the global filter obtains the request path from the general route, and obtains the second-level path data as the microservice name according to the path configuration rule, and the route filter rewrites the request path; the global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule, and the global filter puts the new route into the service network switch and then into the filter chain.

[0115] Figure 6 It is a schematic block diagram of the device for automatically building routes by the gateway provided in the embodiment of the present invention. Figure 2 As Figure 6 shown, in the matching and building unit 307 of the device 300 for automatically building routes by the gateway in this embodiment, it includes: a request putting module 3071, an obtaining module 3072, a rewriting module 3073, a building module 3074, and a route putting module 3075.

[0116] The request putting module 3071 is used for the gateway program to put the client request into the filter chain composed of the route filter and the global filter;

[0117] The obtaining module 3072 is used for the global filter to obtain the request path from the general route and obtain the second-level path data as the microservice name according to the path configuration rule;

[0118] The rewriting module 3073 is used for the route filter to rewrite the request path;

[0119] The building block 3074 is used to construct a new uri object for the global filter, and use the new uri as a parameter to construct a new route according to the path configuration rules.

[0120] The route is placed into the module 3075, where the global filter places the new route into the service network switch and then into the filter chain.

[0121] It should be noted that those skilled in the art can clearly understand the specific implementation processes of the above-mentioned gateway automatic route construction device 300 and each unit module, which can refer to the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and brevity of description, they will not be elaborated here.

[0122] The above-mentioned gateway automatic route construction device can be implemented in the form of a computer program, and this computer program can run on a computer device as Figure 7 shown.

[0123] Please refer to Figure 7 , Figure 7 , which is a schematic block diagram of a computer device provided by an embodiment of the present application. The computer device 500 can be a terminal or a server. Among them, the terminal can be an electronic device with communication functions such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device. The server can be an independent server or a server cluster composed of multiple servers.

[0124] Refer to Figure 7 , the computer device 500 includes a processor 502, a memory, and a network interface 505 connected through a system bus 501. Among them, the memory can include a non-volatile storage medium 503 and an internal memory 504.

[0125] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions, and when these program instructions are executed, the processor 502 can be made to execute a method for automatically constructing a route by a gateway.

[0126] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500.

[0127] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can be made to execute a method for automatically constructing a route by a gateway.

[0128] The network interface 505 is used for network communication with other devices. Those skilled in the art can understand that Figure 6The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the computer device 500 to which the solution of this application is applied. Specifically, the computer device 500 may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

[0129] Among them, the processor 502 is used to run the computer program 5032 stored in the memory to implement the following steps:

[0130] The user configures a general route in the configuration file of the gateway program; the user edits a service network switch in the gateway program, and the service network switch is used to obtain the client request and the general route; the user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route; the user restarts the gateway program; the gateway program reads the configuration of the general route and constructs the general route; the gateway program obtains the client request and the general route through the service network switch; the gateway program matches the general route according to the client request and constructs a new route, and places the new route in the service network switch; the gateway program forwards the client request to the microservice according to the new route.

[0131] In one embodiment, when the processor 502 implements that the user configures a general route in the configuration file of the gateway program, the following steps are specifically implemented:

[0132] Configure the id of the general route as the unique identifier of the route; configure the name of the general route as the route name; configure the uri of the general route as the request path; configure the assertion of the general route as the path configuration rule, and match the general route according to the prefix path of the request path; configure the route filter of the general route as the filter for rewriting the request path.

[0133] In one embodiment, when the processor 502 implements that the user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route, the following steps are specifically implemented:

[0134] The user edits the global filter interface in the gateway program to define the execution behavior of the global filter. The execution behavior of the global filter includes: the global filter obtains the request path from the general route, and obtains the second-level path data as the microservice name according to the path configuration rule; the global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule; the global filter places the new route into the service network switch and then into the filter chain; the user edits the sorting interface in the gateway program to define the execution order of the global filter, including: defining the return value of the getOrder() method in the sorting interface as a value less than 10100, and the smaller the value, the higher the execution priority of the global filter.

[0135] In one embodiment, when the processor 502 implements that the gateway program matches the general route according to the client request, constructs a new route, and places the new route into the service network switch, the specific implementation steps are as follows:

[0136] The gateway program places the client request into the filter chain composed of the route filter and the global filter; the global filter obtains the request path from the general route, and obtains the second-level path data as the microservice name according to the path configuration rule; the route filter rewrites the request path; the global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule; the global filter places the new route into the service network switch and then into the filter chain.

[0137] It should be understood that in the embodiments of the present application, the processor 502 may be a central processing unit (CPU), and this processor 502 may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.

[0138] Those of ordinary skill in the art can understand that all or part of the processes of the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, and this storage medium is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0139] Therefore, the present invention also provides a storage medium. The storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor performs the following steps:

[0140] The user configures a general route in the configuration file of the gateway program; the user edits a service network switch in the gateway program, and the service network switch is used to obtain a client request and the general route; the user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route; the user restarts the gateway program; the gateway program reads the configuration of the general route and constructs the general route; the gateway program obtains the client request and the general route through the service network switch; the gateway program matches the general route according to the client request, constructs a new route, and places the new route into the service network switch; the gateway program forwards the client request to the microservice according to the new route.

[0141] In an embodiment, when the processor executes the computer program to implement that the user configures a general route in the configuration file of the gateway program, the following steps are specifically implemented:

[0142] Configure the id of the general route as the unique identifier of the route; configure the name of the general route as the route name; configure the uri of the general route as the request path; configure the assertion of the general route as the path configuration rule, and match the general route according to the prefix path of the request path; configure the route filter of the general route as the filter for rewriting the request path.

[0143] In an embodiment, when the processor executes the computer program to implement that the user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route, the following steps are specifically implemented:

[0144] The user edits the global filter interface in the gateway program to define the execution behavior of the global filter. The execution behavior of the global filter includes: the global filter obtains the request path from the general route, and obtains the second-level path data as the microservice name according to the path configuration rule; the global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule; the global filter places the new route into the service network switch and then into the filter chain; the user edits the sorting interface in the gateway program to define the execution order of the global filter, including: defining the return value of the getOrder() method in the sorting interface to be a value less than 10100, and the smaller the value, the higher the execution priority of the global filter.

[0145] In one embodiment, when the processor executes the computer program to implement that the gateway program matches a general route according to a client request, constructs a new route, and places the new route in the service network switch, the following steps are specifically implemented:

[0146] The gateway program places the client request into a filter chain composed of a route filter and a global filter; the global filter obtains the request path from the general route, and according to the path configuration rule, obtains the second-level path data as the microservice name; the route filter rewrites the request path; the global filter constructs a new uri object, and uses the new uri as a parameter to construct a new route according to the path configuration rule; the global filter places the new route in the service network switch and then in the filter chain.

[0147] The storage medium may be a variety of computer-readable storage media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disc that can store program code.

[0148] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

[0149] In several embodiments provided by the present invention, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0150] The steps in the method embodiments of the present invention can be adjusted, combined, and deleted according to actual needs. The units in the device embodiments of the present invention can be combined, divided, and deleted according to actual needs. In addition, the functional units in each embodiment of the present invention can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.

[0151] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0152] As described above, the above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. Method for automatically constructing a route by a gateway, characterized in that It includes the following steps: The user configures a general route in the configuration file of the gateway program; The user edits a service network switch in the gateway program, and the service network switch is used to obtain client requests and general routes; The user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route; The user restarts the gateway program; The gateway program reads the configuration of the general route and constructs the general route; The gateway program obtains client requests and general routes through the service network switch; The gateway program matches the general route according to the client request, constructs a new route, and places the new route into the service network switch; The gateway program forwards the client request to the microservice according to the new route; The user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route, including: The user edits the global filter interface in the gateway program to define the execution behavior of the global filter; the execution behavior of the global filter includes: The global filter obtains the request path from the general route and obtains the second-level path data as the microservice name according to the path configuration rule; The global filter constructs a new uri object, uses the new uri as a parameter, and constructs a new route according to the path configuration rule; The global filter places the new route into the service network switch and then into the filter chain.

2. The method for automatically constructing a route by a gateway according to claim 1, wherein The user configures a general route in the configuration file of the gateway program, including: Configuring the id of the general route as the unique route identifier; Configuring the name of the general route as the route name; Configuring the uri of the general route as the request path; Configuring the assertion of the general route as the path configuration rule, and matching the general route according to the prefix path of the request path; Configuring the route filter of the general route as the filter for rewriting the request path.

3. The method for automatically constructing a route by a gateway according to claim 2, wherein The user customizes a global filter in the gateway program, and the global filter is used to automatically construct a new route according to the general route, and further includes: The user edits the sorting interface in the gateway program to define the execution order of the global filter.

4. The method for automatically constructing a route by a gateway according to claim 3, wherein The user edits the sorting interface in the gateway program to define the execution order of the global filter, including: Defining the return value of the getOrder() method in the sorting interface as a value less than 10100, and the smaller the value, the higher the execution priority of the global filter.

5. The method for automatically constructing a route by a gateway according to claim 2, characterized in that, The gateway program matches the general route according to the client request, constructs a new route, and places the new route into the service network switch, including: The gateway program places the client request into the filter chain composed of the route filter and the global filter; The global filter obtains the request path from the general route and obtains the second-level path data as the microservice name according to the path configuration rule; The route filter rewrites the request path; The global filter constructs a new uri object, uses the new uri as a parameter, and constructs a new route according to the path configuration rule; The global filter places the new route into the service network switch and then into the filter chain.

6. Device for automatically constructing a route by a gateway, characterized in that Performing the method according to any one of claims 1-5, including: a configuration unit, an editing unit, a customization unit, a restart unit, a reading and building unit, an acquisition unit, a matching and building unit, and a forwarding unit; The configuration unit is used for the user to configure a general route in the configuration file of the gateway program; The editing unit is used for the user to edit a service network switch in the gateway program, and the service network switch is used to obtain client requests and general routes; The customization unit is used for the user to customize a global filter in the gateway program, and the global filter is used to automatically build a new route according to the general route; The restart unit is used for the user to restart the gateway program; The reading and building unit is used for the gateway program to read the configuration of the general route and build the general route; The acquisition unit is used for the gateway program to obtain client requests and general routes through the service network switch; The matching and building unit is used for the gateway program to match the general route according to the client request, build a new route, and place the new route in the service network switch; The forwarding unit is used for the gateway program to forward the client request to the microservice according to the new route; In the customization unit, the user customizes a global filter in the gateway program, and the global filter is used to automatically build a new route according to the general route, including: The user edits the global filter interface in the gateway program to define the execution behavior of the global filter; the execution behavior of the global filter includes: The global filter obtains the request path from the general route and obtains the second-level path data as the microservice name according to the path configuration rule; The global filter constructs a new uri object, uses the new uri as a parameter, and constructs a new route according to the path configuration rule; The global filter places the new route in the service network switch and then in the filter chain.

7. The apparatus for automatically constructing a route by a gateway according to claim 6, wherein The matching and building unit includes: a request placement module, an acquisition module, a rewriting module, a building module, and a route placement module; The request placement module is used for the gateway program to place the client request in the filter chain composed of the route filter and the global filter; The acquisition module is used for the global filter to obtain the request path from the general route and obtain the second-level path data as the microservice name according to the path configuration rule; The rewriting module is used for the route filter to rewrite the request path; The building module is used for the global filter to construct a new uri object, use the new uri as a parameter, and construct a new route according to the path configuration rule; The route placement module is used for the global filter to place the new route in the service network switch and then in the filter chain.

8. A computer device, characterized in that, The computer device includes a memory and a processor, and a computer program is stored on the memory. When the processor executes the computer program, the method for automatically building a route by the gateway according to any one of claims 1-5 is implemented.

9. A storage medium, characterized in that, The storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by the processor, the method for automatically building a route by the gateway according to any one of claims 1-5 can be implemented.

Citation Information

Patent Citations

  • Method for realizing dynamic routing of micro-service gateway

    CN112804722A

  • API gateway automatic processing system and method

    CN115426219A