An interceptor and an interception-based gateway routing method and device

By deploying an interceptor in the gateway and configuring it through the management backend, complete isolation between the interceptor and the gateway service is achieved, solving the problem in existing technologies where the interceptor cannot be completely isolated from the gateway service, thus ensuring the stability and flexibility of the gateway.

CN117294519BActive Publication Date: 2026-11-27浙江讯盟科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311397659.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-26
Publication Date
2026-11-27
Estimated Expiration
2043-10-26

AI Technical Summary

Technical Problem

In existing gateway routing solutions based on interceptors, the interceptors cannot be completely isolated from the gateway service, which affects the stability of the gateway and makes them inflexible to use, as they cannot be deployed or uninstalled during the operation of the gateway.

Method used

By deploying interceptors in the gateway, configuring the execution order of the interceptors and their association with microservices through the management backend, executing microservices using remote procedure calls, and adjusting the execution order of the interceptor list through the management backend, complete isolation and flexible configuration of the interceptors and gateway services can be achieved.

Benefits of technology

It achieves complete isolation between the interceptor and the gateway service, ensuring the stability of the gateway operation, and supports hot loading and unloading of the interceptor, flexibly adjusting the execution order to adapt to changes in business logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117294519B_ABST
    Figure CN117294519B_ABST
Patent Text Reader

Abstract

The present disclosure belongs to the technical field of computers, and particularly relates to an interceptor and a gateway routing method and device based on the interceptor. The method comprises the following steps: acquiring a microservice request, matching a routing rule based on a path, a uniform resource identifier and parameters of the microservice request; acquiring an interceptor list from the routing rule, and serially executing microservices corresponding to each of the interceptors in the interceptor list based on a preset execution order; and after the microservices corresponding to all the interceptors in the interceptor list are executed, distributing the microservice request to a corresponding microservice processing module based on the routing rule. The present disclosure can realize complete isolation of custom interceptors and gateway services, guarantee the stability of the gateway, and realize loading, unloading and execution order adjustment of the interceptors in the running state of the gateway through configuration, which is very flexible.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure belongs to the field of computer technology, and specifically relates to an interceptor and a gateway routing method and apparatus based on the interceptor. Background Technology

[0002] Gateways need to perform operations such as forwarding, transforming, filtering, encrypting, and load balancing on requests to access business systems and responses from business systems to access requests, thereby achieving functions such as network interconnection, security, caching, and load balancing.

[0003] As the entry point for business systems, gateways must remain stable. However, a medium to large-scale business system may have extensive customization requirements for the entry access layer, which can lead to frequent changes to the gateway's business code and affect the stability of the entire entry gateway.

[0004] In the industry, interceptors are commonly used to isolate minor modifications to the entry point access layer from the core gateway code, thereby improving gateway stability. An interceptor refers to intercepting access requests to the gateway and replacing the gateway's normal processing of these requests with a corresponding interceptor service.

[0005] However, current gateway routing solutions based on interceptors all define and use interceptors using annotations and code, requiring integration into the original gateway project code, which is highly intrusive. They cannot achieve complete independence from the gateway service, still affecting gateway stability. Furthermore, interceptors cannot be deployed or uninstalled based on business logic during gateway operation, making them inflexible. Summary of the Invention

[0006] This disclosure proposes an interceptor-based gateway routing scheme to address the problems of interceptors not being fully isolated from gateway services and being inflexible in existing interceptor-based gateway routing schemes.

[0007] A first aspect of this disclosure provides an interceptor deployed in a gateway for intercepting microservice requests to the gateway. The interceptor includes a corresponding microservice and a management backend, wherein:

[0008] The management backend is used to configure the execution order of the interceptors among multiple interceptors, wherein the multiple interceptors are pre-set in the routing configuration of the gateway;

[0009] The management backend is also used to configure the association between the microservice and the gateway service;

[0010] When configured to be associated, and when the interceptor is executed, the gateway executes the microservice via remote procedure call.

[0011] A second aspect of this disclosure provides a gateway routing method based on an interceptor, comprising:

[0012] Obtain a microservice request, and match routing rules based on the path, Uniform Resource Identifier and parameters of the microservice request, wherein the routing rules include an interceptor list, and the interceptor list includes the interceptors described in the first aspect of the present disclosure.

[0013] The interceptor list is obtained from the routing rules, and the microservices corresponding to each interceptor in the interceptor list are executed sequentially according to a preset execution order.

[0014] After executing all the microservices corresponding to the interceptors in the interceptor list, the microservice requests are assigned to the corresponding microservice processing modules based on the routing rules.

[0015] In some embodiments, the step of sequentially executing the microservices corresponding to each interceptor in the interceptor list based on a preset execution order includes:

[0016] Obtain the preset execution order number for each interceptor in the interceptor list, and execute the microservice corresponding to the interceptor serially based on the execution order number.

[0017] In some embodiments, executing the microservices corresponding to each interceptor in the interceptor list according to a preset execution order includes:

[0018] If the interceptor is the interceptor according to the first aspect of the present disclosure, the execution order number of the interceptors in the interceptor list is adjusted by the management backend so that the interceptors are executed in the target order.

[0019] In some embodiments, executing the microservice corresponding to the interceptor includes:

[0020] If the interceptor is the interceptor according to the first aspect of the present disclosure, the microservice corresponding to the interceptor is executed via remote procedure call, wherein the microservice is pre-configured to be associated with the gateway through the management backend.

[0021] In some embodiments, the step of executing the microservices corresponding to each interceptor in the interceptor list according to a preset execution order further includes:

[0022] If the microservice logic corresponding to any interceptor in the interceptor list blocks the microservice request, then the microservice request is returned and the execution of the microservice corresponding to the subsequent interceptors is stopped.

[0023] In some embodiments, the method further includes:

[0024] The interceptors in the interceptor list process the microservice processing module's response to the microservice request in the reverse order of the preset execution order.

[0025] A third aspect of this disclosure provides a gateway routing apparatus based on an interceptor, characterized in that it includes:

[0026] A matching module is used to obtain microservice requests and match routing rules based on the path, Uniform Resource Identifier and parameters of the microservice requests, wherein the routing rules include interceptor list information, and the interceptor list includes the interceptors according to the first aspect of the embodiments of this disclosure;

[0027] The execution module is used to obtain the interceptor list from the routing rules and execute the microservices corresponding to each interceptor in the interceptor list in a preset execution order.

[0028] The routing module is used to allocate the microservice request to the corresponding microservice processing module based on the routing rules after executing all the microservices corresponding to the interceptors in the interceptor list.

[0029] In summary, the interceptors, interceptor-based gateway routing methods, and interceptor-based gateway routing devices provided in the embodiments of this disclosure achieve complete isolation between custom interceptors and gateway services by using independent microservices. The association between interceptors and gateway services can be completed through configuration via the management backend, thereby ensuring the operational stability of the gateway itself. At the same time, the loading and unloading of interceptors take effect through configuration via the management backend. Adding interceptors to the gateway can be hot-updated while the gateway is running. When it is necessary to change the execution order of interceptors based on business logic, it can be done simply by configuring in the management backend, which is very flexible. Attached Figure Description

[0030] The features and advantages of this disclosure will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the scope of this disclosure in any way.

[0031] Figure 1 This is a schematic diagram of a gateway system to which some embodiments of this disclosure apply;

[0032] Figure 2 This is a flowchart illustrating an interceptor-based gateway routing method according to some embodiments of this disclosure;

[0033] Figure 3 This is a schematic diagram of an interceptor-based gateway routing device according to some embodiments of the present disclosure. Detailed Implementation

[0034] In the following detailed description, numerous specific details of this disclosure are set forth by way of example in order to provide a thorough understanding of the relevant disclosure. However, it will be apparent to those skilled in the art that this disclosure may be practiced without these details. It should be understood that the terms “system,” “apparatus,” “unit,” and / or “module” used in this disclosure are a method of distinguishing different parts, elements, sections, or components at different levels in a sequential arrangement. However, these terms may be replaced by other expressions if they can achieve the same purpose.

[0035] It should be understood that when a device, unit, or module is referred to as being "on," "connected to," or "coupled to" another device, unit, or module, it may be directly connected to or coupled to, or communicate with, other devices, units, or modules, or there may be intermediate devices, units, or modules present, unless the context explicitly indicates otherwise. For example, the term "and / or" as used in this disclosure includes any one and all combinations of one or more of the associated listed items.

[0036] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to limit the scope of this disclosure. As shown in this specification and claims, unless the context clearly indicates otherwise, words such as "a," "an," "an," and / or "the" do not specifically refer to the singular and may include the plural. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified features, integrals, steps, operations, elements, and / or components, and such expressions do not constitute an exclusive list, in which other features, integrals, steps, operations, elements, and / or components may also be included.

[0037] Referring to the following description and accompanying drawings, these and other features and characteristics, operating methods, functions of related structural elements, combinations of parts, and economics of manufacture of this disclosure can be better understood, wherein the description and drawings form part of the specification. However, it is clearly understood that the drawings are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this disclosure. It is understood that the drawings are not drawn to scale.

[0038] Various structural diagrams are used in this disclosure to illustrate various variations of embodiments according to this disclosure. It should be understood that the preceding or following structures are not intended to limit this disclosure. The scope of protection of this disclosure is defined by the claims.

[0039] Figure 1 This is a schematic diagram of a gateway system to which some embodiments of this disclosure apply. Figure 1 The system shown includes a gateway, a business function microservice processing module connected to the gateway, and an interceptor implementation business microservice processing module corresponding to a custom interceptor pre-installed in the gateway. Among them:

[0040] The gateway refers to an HTTP gateway, which is used to perform operations such as forwarding, transformation, filtering, encryption, and load balancing on the microservice requests from the service requester to the business system and the responses from the business system to the microservice requests, in accordance with the rules of the HTTP protocol, thereby realizing functions such as network interconnection, security, caching, and load balancing between the business system and the external network.

[0041] The gateway has built-in routing rules to determine the routing path of the microservice request based on the routing rules, and finally distributes the microservice request to each business function microservice processing module for processing based on the routing path; the gateway is also used to send the response of each business function microservice processing module to the microservice request to the service requester.

[0042] In some embodiments of this disclosure, the routing rules include a list of interceptors.

[0043] An interceptor is a software or hardware module used to intercept access requests to a gateway, replacing the gateway's normal processing flow with the interceptor's corresponding service.

[0044] In some embodiments of this disclosure, interceptors are divided into system interceptors and custom interceptors.

[0045] System interceptors are pre-coded interceptors with specific characteristics that are implemented within the gateway. For example, a rate-limiting interceptor is used to block access requests that exceed the access QoS limit within a preset time period.

[0046] Custom interceptors refer to personalized interceptors developed based on business logic according to development specifications and entry points. Custom interceptor developers can develop independent microservices corresponding to their custom interceptors according to interface specifications. The custom interceptor microservice processing module is associated with the gateway service via PRC (Remote Procedure Call). For example, to provide an access management service, a custom access management interceptor can be defined to intercept access requests, and the corresponding microservice can then perform access permission checks on the requester of the intercepted access request for the requested service.

[0047] In some embodiments of this disclosure, the interceptors in the interceptor list form a linear chain based on their respective execution order numbers. After a service request passes through the gateway entry layer, it obtains the routing configuration information, where the interceptor link group information contains all the interceptor information required by the current request. The system executes each interceptor linearly according to the interceptor order and name in the configuration information.

[0048] The gateway includes an interceptor management backend. Through the configuration page of the management backend, administrators can associate custom interceptor microservice processing modules with the gateway service. In particular, administrators can adjust the execution order of custom interceptors in the linear chain so that the custom interceptors execute in a preset order required by the business logic.

[0049] Figure 2 This is a flowchart illustrating an interceptor-based gateway routing method according to some embodiments of the present disclosure. In some embodiments, the interceptor-based gateway routing method may be... Figure 1 The gateway of the system shown is executed. For example... Figure 2 As shown, the gateway routing method based on interceptors includes the following steps:

[0050] S210, Obtain a microservice request, and match routing rules based on the path, Uniform Resource Identifier, and parameters of the microservice request, wherein the routing rules include an interceptor list, and the interceptor list includes the interceptors as described in claim 1.

[0051] Specifically, such as Figure 1 The gateway shown is pre-configured with routing rules, which include: route name, UriPattern, ProxyPass, UpStream, and a series of interceptors that handle intermediate processing.

[0052] Route name: The identifier for the routing rule, used for backend management.

[0053] UriPattern (e.g., / path / *.json, / test / a / * / ) is a regular expression for the request path. It is the entry point for all HTTP requests to enter the gateway, and the gateway uses this information to match the corresponding routing rules.

[0054] ProxyPass: A reverse proxy that forwards requests based on URIs (Uniform Resource Identifiers) to a predefined application server.

[0055] UpStream: A load balancer that defines multiple service nodes that need to be proxied under the same naming rule; an UpStream includes multiple IP ports. When used in conjunction with a reverse proxy, ProxyPass can proxy to a specific IP port or to an UpStream.

[0056] When a service request enters the gateway, it is first matched to a routing rule based on the request path, Uniform Resource Identifier, parameters, and other rules.

[0057] The matching logic is based on the configuration rules of URIPattern.

[0058] For example, if you configure the URI pattern as / open / file / , all URLs with a path starting with / open / file / that enter the gateway will match the current routing rule, such as: http: / / ip:port / open / file / create;

[0059] http: / / ip:port / open / file / detail.

[0060] However, when the URI pattern is configured as / open / file / *.json,

[0061] If the request file extension is *.json, neither of the above two paths will match the current routing rule.

[0062] For example: http: / / ip:port / open / file / create.json

[0063] If the match fails, the route will return a 404 status code.

[0064] S220, obtain the interceptor list from the routing rules, and execute the microservices corresponding to each interceptor in the interceptor list in a preset execution order.

[0065] Specifically, the routing configuration is obtained based on the routing rules and then refreshed to the local memory. The routing configuration includes interceptor information.

[0066] The list of interceptors will be arranged into a linear chain that executes sequentially according to the order configured by the administrator.

[0067] Once a request enters the interceptor chain, the interceptors are executed sequentially. If any interceptor logic blocks the service request, it will return immediately and will not proceed further.

[0068] Interceptors include system interceptors and custom interceptors. If the interceptor being executed is a custom interceptor, the system will find the system identifier of the current interceptor and the microservice corresponding to the interceptor. The system will then execute the target microservice via RPC call to achieve the interception function.

[0069] Custom interceptors refer to personalized interceptors developed based on business logic in accordance with development specifications and entry points.

[0070] The gateway defines a custom interceptor interface and its input and output parameters. These include: input parameter structures: request URI, Method, Headers, Cookies; output parameter structures: response Body, Headers, Cookies; and the processor interface name: process(request, response, extra).

[0071] Developers can implement custom interceptors on independent microservices according to the interface specifications, and associate them with the gateway service via remote RPC calls. Developers need to define a unique interceptor name within the system, used for routing when the gateway executes the custom interceptor for remote calls. They can also freely extend the `extra` parameter, which is passed to the final implementation code of the interceptor by the gateway configuration administrator through a user interface, and the implementation is customized based on the extended values.

[0072] Administrators can adjust the execution order number of interceptors in the interceptor list through the management backend so that custom interceptors are executed in the order required to achieve the business logic objectives.

[0073] By using custom interceptors, the following features can be achieved:

[0074] Code isolation: By using independent microservices to implement custom interceptors, the gateway service is kept separate, ensuring the stability of the gateway itself. The association can be completed through a graphical configuration method.

[0075] Hot reloading: The loading and unloading of interceptors are entirely configured to take effect. Adding interceptors to the gateway allows for hot updates to be performed at runtime.

[0076] Multi-language support: Due to the independence of the service, there are no restrictions on the development language of the interceptor. As long as it meets the interface specifications and RPC framework mechanism, it can be written in any language. Commonly used languages ​​include Java, C++, Golang, Python, Node.js, etc.

[0077] Observable: The system records the response time and call chain of each interceptor. Gateway administrators can visually manage the performance metrics and business call relationships of each interceptor, enabling timely and accurate handling of specific interceptors in case of failures or extreme situations.

[0078] S230, after executing all the microservices corresponding to the interceptors in the interceptor list, the microservice request is assigned to the corresponding microservice processing module based on the routing rules.

[0079] Specifically, after all the interceptors are completed, the route distributor ultimately allocates the access requests to specific microservice processing modules based on proxy rules and load balancing rules to complete the logical processing of the service requests.

[0080] The proxy rule refers to the configuration of ProxyPass in S210, and the load balancing rule refers to the configuration of UPStream in S210.

[0081] The microservice processing module's response to microservice requests also passes through each interceptor. Each interceptor can perform secondary encapsulation of the response value according to custom logic. The response logic is in reverse order, and the interceptor list is arranged in reverse order to form an executable offline chain, which processes the response packet and finally returns it.

[0082] Figure 3 This is a schematic diagram of an interceptor-based gateway routing device according to some embodiments of the present disclosure. Figure 3 As shown, the interceptor-based gateway routing device 300 includes a matching module 310, an execution module 320, and a routing module 330. The interceptor-based gateway routing function can be provided by... Figure 1 The gateway of the system shown is executed. Wherein:

[0083] Matching module 310 is used to obtain microservice requests and match routing rules based on the path, Uniform Resource Identifier, and parameters of the microservice requests. The routing rules include an interceptor list, which contains information about interceptors. Figure 2 The interceptor described in S210-S230;

[0084] Execution module 320 is used to obtain the interceptor list from the routing rules and execute the microservices corresponding to each interceptor in the interceptor list in a preset execution order.

[0085] The routing module 330 is used to allocate the microservice request to the corresponding microservice processing module based on the routing rules after executing all the microservices corresponding to the interceptors in the interceptor list.

[0086] In summary, the interceptors, interceptor-based gateway routing methods, and interceptor-based gateway routing devices provided in the embodiments of this disclosure achieve complete isolation between custom interceptors and gateway services by using independent microservices. The association between interceptors and gateway services can be completed through configuration via the management backend, thereby ensuring the operational stability of the gateway itself. At the same time, the loading and unloading of interceptors take effect through configuration via the management backend. Adding interceptors to the gateway can be hot-updated while the gateway is running. When it is necessary to change the execution order of interceptors based on business logic, it can be done simply by configuring in the management backend, which is very flexible.

[0087] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the devices and modules described above can be referred to the corresponding descriptions in the foregoing device embodiments, and will not be repeated here.

[0088] Although the subject matter described herein is provided in the general context of execution on a computer system in conjunction with an operating system and applications, those skilled in the art will recognize that other implementations can also be executed in conjunction with other types of program modules. Generally, program modules include routines, programs, components, data structures, and other types of structures that perform specific tasks or implement specific abstract data types. Those skilled in the art will understand that the subject matter described herein can be practiced using other computer system configurations, including handheld devices, multiprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframes, etc., and can also be used in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules may reside on both local and remote memory storage devices.

[0089] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.

[0090] It should be understood that the specific embodiments described above are merely illustrative or explanatory of the principles of this disclosure and do not constitute a limitation thereof. Therefore, any modifications, equivalent substitutions, improvements, etc., made without departing from the spirit and scope of this disclosure should be included within the protection scope of this disclosure. Furthermore, the appended claims are intended to cover all variations and modifications falling within the scope and boundaries of the appended claims, or equivalent forms of such scope and boundaries.

Claims

1. An interceptor, deployed in a gateway, for intercepting microservice requests to the gateway, characterized in that, The interceptor corresponds to a microservice deployed independently of the gateway, which includes a management backend, wherein: The microservice is developed based on a predefined interface specification. The interface specification defines the input parameter structure and output parameter structure of the interceptor. The input parameter structure includes the request URI, Method, Headers, and Cookies. The output parameter structure includes the response Body, Headers, and Cookies. The management backend is used to configure the execution order of the interceptors among multiple interceptors, wherein the multiple interceptors are pre-set in the routing configuration of the gateway; The management backend is also used to configure the association between the microservice and the gateway service, wherein the loading and unloading of the microservice takes effect through the configuration of the management backend when the gateway is running. When the microservice is configured to be associated with the gateway service, and when the interceptor is executed, the gateway executes the microservice via remote procedure call.

2. A gateway routing method based on interceptors, characterized in that, include: Obtain a microservice request, and match routing rules based on the path, Uniform Resource Identifier, and parameters of the microservice request, wherein the routing rules include an interceptor list, and the interceptor list includes the interceptors as described in claim 1; The interceptor list is obtained from the routing rules, and the microservices corresponding to each interceptor in the interceptor list are executed sequentially according to a preset execution order. After executing all the microservices corresponding to the interceptors in the interceptor list, the microservice requests are assigned to the corresponding microservice processing modules based on the routing rules.

3. The method according to claim 2, characterized in that, The step of sequentially executing the microservices corresponding to each interceptor in the interceptor list based on a preset execution order includes: Obtain the preset execution order number for each interceptor in the interceptor list, and execute the microservice corresponding to the interceptor serially based on the execution order number.

4. The method according to claim 3, characterized in that, The step of executing the microservices corresponding to each interceptor in the interceptor list according to a preset execution order includes: If the interceptor is the interceptor according to claim 1, the execution order number of the interceptors in the interceptor list is adjusted through the management backend so that the interceptors are executed in the target order.

5. The method according to claim 4, characterized in that, The microservices that execute the interceptors include: The interceptor's corresponding microservice is executed via remote procedure call, wherein the microservice is pre-configured to be associated with the gateway through the management backend.

6. The method according to claim 2, characterized in that, The step of executing the microservices corresponding to each interceptor in the interceptor list based on a preset execution order also includes: If the microservice logic corresponding to any interceptor in the interceptor list blocks the microservice request, then the microservice request is returned and the execution of the microservice corresponding to the subsequent interceptors is stopped.

7. The method according to claim 2, characterized in that, Also includes: The interceptors in the interceptor list process the microservice processing module's response to the microservice request in the reverse order of the preset execution order.

8. A gateway routing device based on an interceptor, characterized in that, include: A matching module is used to obtain microservice requests and match routing rules based on the path, Uniform Resource Identifier and parameters of the microservice requests, wherein the routing rules include an interceptor list, and the interceptor list includes the interceptors as described in claim 1. The execution module is used to obtain the interceptor list from the routing rules and execute the microservices corresponding to each interceptor in the interceptor list in a preset execution order. The routing module is used to allocate the microservice request to the corresponding microservice processing module based on the routing rules after executing all the microservices corresponding to the interceptors in the interceptor list.

Citation Information

Patent Citations

  • API gateway automatic processing system and method

    CN115426219A

  • Remote procedure call processing method and device based on API gateway

    CN116074337A