Transaction route configuration method and system of API gateway

By building an API gateway based on Spring Cloud Gateway and dynamically managing routing, the system instability caused by uncertainty in routing rules changes is solved, and adapting to business growth and the stability and availability of microservice systems are achieved.

CN119996185APending Publication Date: 2025-05-13WUHAN ZBANK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510252640.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-05
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

In the prior art, as business complexity increases, the changes in routing rules are uncertain, and the need to frequently modify routing rules in configuration files or databases and restart gateway services, resulting in the challenge of system stability and availability.

Method used

Build an API gateway based on Spring Cloud Gateway, and configure the basic functions of the API gateway by setting up routing management policies and Filter chain-based methods to dynamically manage the routing of back-end services.

Benefits of technology

It has achieved adaptation to business growth, ensured the stability and availability of the microservice system, and avoided the instability caused by frequent configuration modification and restarting the gateway.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119996185A_ABST
    Figure CN119996185A_ABST
Patent Text Reader

Abstract

The invention provides a transaction route configuration method and system of an API gateway. The method comprises the following steps: constructing the API gateway based on Spring Cloud Gateway; setting a routing management strategy of the API gateway; and according to a routing mode in the routing management strategy, basic functions of the API gateway are configured based on a Filter chain mode. According to the transaction routing configuration method of the API gateway, provided by the invention, routing management strategy and basic function configuration are carried out on routing for dynamically managing back-end services on the basis of Spring Cloud Gateway, so that the requirement of business growth is met, and the stability and availability of a micro-service system are guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information technology, and in particular to a transaction routing configuration method and system for an API gateway. Background Art

[0002] Currently, gateway routing rules are configured mainly using configuration files and reading from the database. When the gateway is started, the configuration rules are loaded to implement routing for existing services or systems. However, as the complexity of the business grows, changes in routing rules will also become uncertain. It is necessary to modify the routing rules in the configuration file or database each time and restart the gateway service, which poses a huge challenge to the stability and availability of the system.

[0003] Based on Spring Cloud Gateway, it implements routing for dynamic management of backend services. The main purpose is to solve the problem that the current cluster contains both Spring Cloud architecture applications and SSH architecture applications, and to achieve unified management of all backend services by the gateway and traffic distribution of business, so as to meet the implementation of unified processing logic on the gateway. It also provides easy-to-use configuration capabilities for easy maintenance. Summary of the invention

[0004] The present application provides a transaction routing configuration method and system for an API gateway, which can solve the technical problem in the prior art that as the complexity of the business increases, the changes in routing rules will also become uncertain, and it is necessary to modify the routing rules in the configuration file or database each time and restart the gateway service, which poses a very great challenge to the stability and availability of the system.

[0005] In a first aspect, the present application provides a transaction routing configuration method for an API gateway, comprising the following steps:

[0006] Build an API gateway based on Spring Cloud Gateway;

[0007] Set the routing management strategy of the API gateway;

[0008] According to the routing mode in the routing management strategy, the basic functions of the API gateway are configured based on the Filter chain.

[0009] In combination with the first aspect, in one implementation, building an API gateway based on Spring Cloud Gateway specifically includes the following steps:

[0010] Create a Spring Boot project;

[0011] Based on the created Spring Boot project, add dependencies to the project object model in XML format to build the API gateway.

[0012] In combination with the first aspect, in one implementation, setting a routing management strategy for an API gateway specifically includes the following steps:

[0013] Get the communication method between microservices;

[0014] Depending on the communication method between microservices, control the execution of different routing strategies.

[0015] In combination with the first aspect, in one implementation, controlling the execution of different routing strategies according to the communication mode between microservices specifically includes the following steps:

[0016] When microservices communicate directly, routing between microservices is performed based on the service list;

[0017] When microservices communicate through a gateway, multiple routing policies are defined for the connection relationship between the microservice and the gateway. The gateway performs service routing by matching the routing policies in the order of the multiple routing policies defined by the filter.

[0018] In combination with the first aspect, in one implementation, when microservices communicate directly with each other, installing a service list to execute routing between microservices specifically includes the following steps:

[0019] Get the service name of the microservice;

[0020] Divide microservices into service clusters according to service names;

[0021] When microservices communicate directly with each other, service routing is performed for each service cluster based on the service list.

[0022] In combination with the first aspect, in one implementation, configuring the basic functions of the API gateway based on the Filter chain in accordance with the routing mode in the routing management policy specifically includes the following steps:

[0023] Get the routing mode in the routing management policy;

[0024] Implement different basic function configuration strategies of API gateway for different routing modes.

[0025] In combination with the first aspect, in one implementation, executing different basic function configuration strategies of the API gateway for different routing modes specifically includes the following steps:

[0026] When the routing mode is normal routing mode, configure the routing name, matching routing and actual address pointed to by URI routing, hiding URI prefix and whether to enable fuse;

[0027] When the routing mode is advanced routing mode, configure the parameters of filters and predicates.

[0028] In a second aspect, the present application provides a transaction routing configuration system for an API gateway, including:

[0029] Gateway building module, used to build API gateway based on Spring Cloud Gateway;

[0030] A routing management strategy setting module, which is in communication with the gateway building module and is used to set the routing management strategy of the API gateway;

[0031] The basic function configuration module is communicated with the routing management policy setting module and is used to configure the basic functions of the API gateway based on the Filter chain according to the routing mode in the routing management policy.

[0032] In conjunction with the second aspect, in one implementation, the basic function configuration module includes:

[0033] A routing mode acquisition unit, used to acquire the routing mode in the routing management policy;

[0034] The basic function configuration unit is in communication with the routing mode acquisition unit and is used to execute different basic function configuration strategies of the API gateway for different routing modes.

[0035] In a third aspect, the present application provides a computer-readable storage medium, characterized in that a transaction routing configuration program of an API gateway is stored on the computer-readable storage medium, wherein when the transaction routing configuration program of the API gateway is executed by a processor, the steps of the transaction routing configuration method of the API gateway as described above are implemented.

[0036] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:

[0037] The transaction routing configuration method of the API gateway provided in this application is based on Spring Cloud Gateway, and implements routing management strategies and basic function configurations for dynamically managing backend services to meet the needs of business growth and ensure the stability and availability of the microservice system. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A flowchart of a transaction routing configuration method for an API gateway provided in an embodiment of the present application;

[0039] Figure 2 An illustration of the service registration center provided in the embodiment of the present application;

[0040] Figure 3 A topology diagram of the transaction routing configuration method of the API gateway provided in the embodiment of the present application;

[0041] Figure 4 A diagram illustrating a routing mode provided in an embodiment of the present application;

[0042] Figure 5 A diagram illustrating the configuration of basic functions in the common routing mode provided in the embodiment of the present application;

[0043] Figure 6 A functional module block diagram of the transaction routing configuration system of the API gateway provided in an embodiment of the present application. DETAILED DESCRIPTION

[0044] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0045] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.

[0046] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.

[0047] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.

[0048] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.

[0049] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0050] First, as Figure 1 As shown, the embodiment of the present application provides a transaction routing configuration method for an API gateway, comprising the following steps:

[0051] Step S1: Build an API gateway based on Spring Cloud Gateway;

[0052] Step S2: Set the routing management strategy of the API gateway;

[0053] Step S3: According to the routing mode in the routing management policy, configure the basic functions of the API gateway based on the Filter chain.

[0054] The transaction routing configuration method of the API gateway provided in this application is based on Spring Cloud Gateway, and implements routing management strategies and basic function configurations for dynamically managing backend services to meet the needs of business growth and ensure the stability and availability of the microservice system.

[0055] In one embodiment, the step S1: building an API gateway, more specifically, building an API gateway based on Spring Cloud Gateway, more specifically, includes the following steps:

[0056] Step S11: Create a Spring Boot project. Specifically, you can use Spring Initializr (https: / / start.spring.io / ) to quickly create a Spring Boot project. When creating a Spring Boot project, add the Spring Cloud Gateway dependency.

[0057] Step S12: Based on the created Spring Boot project, add dependencies to the project object model in XML format to build an API gateway; specifically, add the dependency of Spring Cloud Gateway in pom.xml.

[0058] In one embodiment, the step S2: setting the routing management strategy of the API gateway specifically includes the following steps:

[0059] Step S21: Obtain the communication method between microservices;

[0060] Step S22: Control and execute different routing strategies according to the communication mode between microservices.

[0061] This application is based on the API gateway and provides different routing strategies for microservices with different communication methods.

[0062] In one embodiment, the step S22: controlling the execution of different routing strategies according to the communication mode between microservices specifically includes the following steps:

[0063] Step S221: When microservices communicate directly with each other, routing between microservices is performed according to the service list; specifically, the service registration / discovery module in the service running instance periodically pulls the service list from the service registration center to the local cache. When microservices communicate directly without passing through the service gateway, service routing is completed according to the running service instance. At the same time, the service instance provides the monitoring endpoint of the application and completes the heartbeat detection with the registration center, such as Figure 2 As shown;

[0064] Step S222: When microservices communicate with each other through the gateway, multiple routing policies are defined for the connection relationship between the microservice and the gateway, and the gateway performs service routing by matching the routing policies in the order of the multiple routing policies defined by the filter.

[0065] In one embodiment, the step S221: when microservices communicate directly with each other, installing a service list to perform routing between microservices specifically includes the following steps:

[0066] Get the service name of the microservice;

[0067] Microservices are divided into service clusters according to the service name. The gateway obtains the specific instance of the service from the registration center, forming a topology diagram as shown in the following figure. Figure 3 As shown;

[0068] When microservices communicate directly with each other, service routing is performed for each service cluster based on the service list.

[0069] In one embodiment, the step S3: configuring the basic functions of the API gateway based on the Filter chain according to the routing mode in the routing management policy, specifically includes the following steps:

[0070] Step S31: Obtain the routing mode in the routing management policy, the routing mode includes the advanced routing mode and the common routing mode, such as Figure 4 As shown;

[0071] Step S32: Execute different basic function configuration strategies of the API gateway for different routing modes.

[0072] In one embodiment, the step S32: executing different basic function configuration strategies of the API gateway for different routing modes specifically includes the following steps:

[0073] Step S321: When the routing mode is the normal routing mode, the routing name, the matching route and the actual address pointed to by the URI routing, the hidden URI prefix and whether the fuse is enabled or not are configured;

[0074] Step S322: When the routing mode is the advanced routing mode, configure the parameters of the filter and predicate.

[0075] In one embodiment, when the routing mode is the normal routing mode, a mapping definition is performed between the access address and the routing address of the microservice, and URI routing forwarding is performed by matching the access address. The access address path of the gateway, such as configuring myroute / test, then the access address is: gateway address / myroute / test, and the access type supports get and post methods. The actual forwarded address can be a specific http address, and it also supports local access to the cluster, such as load balancing such as lb: / / auth-service / auth / getUsers. The beginning of lb means load balancing, and auth-service is the service name of the corresponding service registered in eureka. After the route is successfully added, a connection will appear on the topology page of the gateway management end. If the URI is configured to start with lb, a connection will be added to the corresponding service. If the URI is the address of an instance, a separate dotted line will be configured to connect to the corresponding instance, and the connection from the service to the instance will also be marked in bold, such as Figure 5 shown.

[0076] In one embodiment, in step S321, when the routing mode is the common routing mode, the routing name, the matching routing and the actual address pointed to by the URI routing, the hidden URI prefix and whether the fuse is enabled are configured as follows:

[0077] Route name: You can fill in any value (without @ and $ symbols);

[0078] Matching path: The path of the gateway that executes the route. For example, if myroute / test is configured, the access address is: gateway address / myroute / test. In normal routing mode, the corresponding leading slash ' / ' can be left blank and will be automatically filled in by the backend.

[0079] URI: The actual address pointed by the route, which can be the actual address; it can also be a load balancing such as lb: / / auth-service / auth / getUsers. The lb at the beginning means that load balancing is used, and auth-service is the service name registered in eureka. When adding a normal route, the front-end will automatically spell the previous uri. For example, if you add a route to the service auth-service, it will automatically spell lb: / / auth-service, and the subsequent uri can be filled in manually by the user, and then the back-end will automatically write the corresponding filter;

[0080] Hide URI prefix: Enabled by default. If disabled, the mapping relationship will be as follows: gateway address / myroute / getUsers is mapped to: actual address / myroute / getUsers. If enabled, the mapping will become actual address / getUsers.

[0081] Whether to enable circuit breaker: Select whether to enable circuit breaker. In normal mode, the default circuit breaker configuration is used, and the default circuit breaker configuration can be configured in the configuration file. By default, the circuit breaker will be blown after a timeout of 3000ms. After turning on the circuit breaker, you can also configure the downgrade uri. When the route is determined to be circuit-broken, the original request will be forwarded to the specified uri. The uri here is the internal uri of the gateway. For example, if you configure getUsers, it is actually: gateway address / getUsers. If you want to direct to external applications, you need to configure another route and match the matching path with the uri. The route configuration is as follows:

[0082] Interface call: 127.0.0.1:8081 / oms / gateway / route / addList / classic

[0083] Message: [

[0085] {

[0086] "id":"branch-trade",

[0087] "path":" / branch-trade",

[0088] "hystrix_flag":"false",

[0089] "fallabck_uri":"fallbackTest07",

[0090] "strip_prefix":"true",

[0091] "uri":"lb: / / branch-trade"

[0092] } ]

[0094] In one embodiment, for some special scenarios, such as the same interface can access different microservices, advanced routing is required to implement URI request routing. Step S322: When the routing mode is the advanced routing mode, the parameters of the filter and predicate are configured. Specifically, the filter and predicate are manually configured in the advanced mode, wherein the parameters of the filter and predicate are built-in and support extension. The advanced routing definition can be selected from the already defined filters and predicates, and supports a variety of flexible policy definitions, as shown in Table 1:

[0095] Table 1 Filter table

[0096]

[0097]

[0098] Table 2 Predicate table

[0099]

[0100]

[0101] Second, as Figure 6As shown, the present application provides a transaction routing configuration system for an API gateway, including a gateway construction module 100, a routing association policy setting module 200 and a basic function configuration module 300. The gateway construction module 100 is used to build an API gateway based on Spring Cloud Gateway; the routing management policy setting module 200 is communicated with the gateway construction module 100 and is used to set the routing management policy of the API gateway; the basic function configuration module 300 is communicated with the routing management policy setting module 200 and is used to configure the basic functions of the API gateway based on the Filter chain according to the routing mode in the routing management policy.

[0102] In one embodiment, the basic function configuration module includes:

[0103] A routing mode acquisition unit, used to acquire the routing mode in the routing management policy;

[0104] The basic function configuration unit is in communication connection with the routing mode acquisition unit, and is used to execute different basic function configuration strategies of the API gateway for different routing modes. Among them, the functional implementation of each module in the transaction routing configuration system of the API gateway corresponds to each step in the embodiment of the transaction routing configuration method of the API gateway, and its functions and implementation processes are not repeated here one by one.

[0105] In a third aspect, an embodiment of the present application provides a transaction routing configuration device for an API gateway. The transaction routing configuration device for an API gateway may be a personal computer (PC), a laptop computer, a server, or other device with data processing capabilities.

[0106] The communication interface includes input / output (I / O) interface, physical interface and logical interface, etc., which are used to realize the interconnection of devices inside the transaction routing configuration device of the API gateway, and the interface used to realize the interconnection between the transaction routing configuration device of the API gateway and other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, a fiber optic interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.

[0107] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.

[0108] The processor may be a general-purpose processor, which may call the transaction routing configuration program of the API gateway stored in the memory and execute the transaction routing configuration method of the API gateway provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). Among them, the method executed when the transaction routing configuration program of the API gateway is called may refer to the various embodiments of the transaction routing configuration method of the API gateway of the present application, which will not be repeated here.

[0109] In a fourth aspect, an embodiment of the present application also provides a readable storage medium.

[0110] The readable storage medium of the present application stores a transaction routing configuration program of the API gateway, wherein when the transaction routing configuration program of the API gateway is executed by the processor, the steps of the transaction routing configuration method of the API gateway as described above are implemented.

[0111] Among them, the method implemented when the transaction routing configuration program of the API gateway is executed can refer to the various embodiments of the transaction routing configuration method of the API gateway of the present application, and will not be repeated here.

[0112] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.

[0113] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.

[0114] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A transaction routing configuration method for an API gateway, characterized in that: The following steps are involved: Build an API gateway based on Spring Cloud Gateway; Set the routing management strategy of the API gateway; According to the routing mode in the routing management strategy, the basic functions of the API gateway are configured based on the Filter chain.

2. The transaction routing configuration method of the API gateway according to claim 1, characterized in that: The construction of API gateway based on SpringCloud Gateway specifically includes the following steps: Create a Spring Boot project; Based on the created Spring Boot project, add dependencies to the project object model in XML format to build the API gateway.

3. The transaction routing configuration method of the API gateway according to claim 1, characterized in that: The routing management strategy of setting the API gateway specifically includes the following steps: Get the communication method between microservices; Depending on the communication method between microservices, control the execution of different routing strategies.

4. The transaction routing configuration method of the API gateway as claimed in claim 3, characterized in that: According to the communication mode between microservices, controlling and executing different routing strategies specifically includes the following steps: When microservices communicate directly, routing between microservices is performed based on the service list; When microservices communicate through a gateway, multiple routing policies are defined for the connection relationship between the microservice and the gateway. The gateway performs service routing by matching the routing policies in the order of the multiple routing policies defined by the filter.

5. The transaction routing configuration method of the API gateway according to claim 4, characterized in that: When microservices communicate directly with each other, the service list is installed to execute routing between microservices, which specifically includes the following steps: Get the service name of the microservice; Divide microservices into service clusters according to service names; When microservices communicate directly with each other, service routing is performed for each service cluster based on the service list.

6. The transaction routing configuration method of the API gateway according to claim 1, characterized in that: According to the routing mode in the routing management strategy, the basic functions of the API gateway are configured based on the Filter chain, which specifically includes the following steps: Get the routing mode in the routing management policy; Implement different basic function configuration strategies of API gateway for different routing modes.

7. The transaction routing configuration method of the API gateway according to claim 6, characterized in that: The basic function configuration strategies of executing different API gateways for different routing modes specifically include the following steps: When the routing mode is normal routing mode, configure the routing name, matching routing and actual address pointed to by URI routing, hiding URI prefix and whether to enable fuse; When the routing mode is advanced routing mode, configure the parameters of filters and predicates.

8. A transaction routing configuration system for an API gateway, characterized in that: include: Gateway building module, used to build API gateway based on Spring Cloud Gateway; A routing management strategy setting module, which is in communication with the gateway building module and is used to set the routing management strategy of the API gateway; The basic function configuration module is communicated with the routing management policy setting module and is used to configure the basic functions of the API gateway based on the Filter chain according to the routing mode in the routing management policy.

9. The transaction routing configuration system of the API gateway according to claim 8, characterized in that: The basic function configuration module includes: A routing mode acquisition unit, used to acquire the routing mode in the routing management policy; The basic function configuration unit is in communication with the routing mode acquisition unit and is used to execute different basic function configuration strategies of the API gateway for different routing modes.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a transaction routing configuration program for an API gateway, wherein when the transaction routing configuration program for an API gateway is executed by a processor, the steps of the transaction routing configuration method for an API gateway as described in any one of claims 1 to 7 are implemented.