A Method and Device for Customizing Interface Timeout
By creating a rewrite timeout logic process in the gateway and reconstructing the routing metadata, the problem of insufficient timeout control in the existing gateway technology is solved, and the interface-level timeout time customization is realized, ensuring the stability and data reliability of the system when traffic fluctuates.
Patent Information
- Application Number
- CN202211488406.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2042-11-25
AI Technical Summary
In the microservice architecture, the minimum granularity of timeout control can only reach the routing level, and it is impossible to personalize the timeout time setting for individual time-consuming interfaces, resulting in the risk of downtime when traffic fluctuates.
When the gateway processes the request, create a rewrite timeout logical process, obtain the requested URI through the Pre-Filter filter, and reconstruct the new routing metadata based on the interface's routing metadata after the matching is successful, overwrite the original configuration, and implement interface-level timeout customization.
It realizes the setting and delivery of any interface timeout parameters under any route, avoids interface interrupts caused by the short unified timeout time, and ensures the stability of the system and the reliability of data acquisition.
Smart Images

Figure CN115866023B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of gateways, and in particular, to a method and device for customizing interface timeout time. Background Art
[0002] In a microservices architecture, usually a system is split into multiple microservices. To respond to client calls to microservices, the concept of a gateway is introduced. The gateway provides simple, effective, and unified API routing management for the microservices architecture system. As the unified entry of the system, it provides routing transfer for internal services, provides unified services to clients, and can implement some common logics that are not coupled with the business. Its main functions include authentication, authorization, routing forwarding, security policies, anti-brushing, traffic control, monitoring logs, etc.
[0003] Existing gateway technologies such as Spring Cloud Gateway provide the following two-dimensional supports in the timeout control function module: global timeout configuration and routing timeout configuration. Among them, the global timeout configuration takes effect for all routes and all interfaces. The routing timeout configuration takes effect for all interfaces under a specific route and takes precedence over the global timeout configuration.
[0004] However, the above two timeout configuration schemes have the following defects and deficiencies in use:
[0005] The minimum granularity of timeout control for both schemes can only reach the route level. In fact, only a few interfaces under a route take relatively long time, and more than 95% of the interfaces take relatively short time. Configuring a relatively large timeout time according to the route will bring a risk of downtime to the application and the server if timely timeout fusing is not performed in case of traffic fluctuations. Summary of the Invention
[0006] The purpose of the present invention is to provide a method and device for customizing interface timeout time, which helps to solve the above technical problems.
[0007] The present invention is implemented as follows:
[0008] In the first aspect, the present invention provides a method for customizing interface timeout time, including the following steps:
[0009] Step 1, when the gateway processes a request, create a rewritten timeout logic process that is preferentially executed in the process.
[0010] Step 2, after the request enters the gateway, obtain the URI of the request and match it with the rewritten timeout logic process; if the match is successful, execute Step 3; if the match is unsuccessful, do not perform the operation of defining the timeout time for the interface.
[0011] Step 3: Execute the rewrite timeout logic process, that is, based on the routing metadata of the successfully matched interface, the rewrite timeout logic process reconstructs new routing metadata and overwrites the original routing metadata.
[0012] In the above technical solution, further, in Step 1, a Pre-Filter is used to implement the preferential execution of the rewrite timeout logic process.
[0013] In any of the above technical solutions, further, in Step 2, a Pre-Filter is used to obtain the URI of the request.
[0014] In any of the above technical solutions, further, in Step 1, the gateway configuration is increased.
[0015] In any of the above technical solutions, further, in Step 1, additional interfaces are constructed in the gateway.
[0016] In any of the above technical solutions, further, in Step 1, the rewrite timeout logic process is loaded into the server memory.
[0017] In a second aspect, the present invention provides a device based on the above interface timeout time customization method, including a processing module, where the processing module is used to call the rewrite timeout logic process, to determine whether the URI of the request matches the rewrite timeout logic process, and to execute the rewrite timeout logic process in the gateway.
[0018] Further, the interface timeout time customization device further includes a storage module for storing the rewrite timeout logic process.
[0019] Further, the interface timeout time customization device further includes a parsing module for obtaining the URI of the request.
[0020] Compared with the prior art, the beneficial effects of the present invention are:
[0021] The interface timeout time customization method and device of the present invention rewrite the timeout parameters before the interface request in the gateway, realizing the setting and transmission of the timeout parameters of any interface under any route in the gateway, ensuring that the overall routing timeout is not affected, and solving the problem that all interfaces share one configuration. Through this method and device, it can solve the problem that specific interfaces with long time-consuming are interrupted due to a short unified timeout time, resulting in users being unable to obtain data normally. Description of the Drawings
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the accompanying drawings required for the embodiments. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0023] Figure 1 It is a schematic flowchart of the method for customizing the interface timeout time of the present invention;
[0024] Figure 2 It is a schematic structural diagram of the device for customizing the interface timeout time of the present invention. Specific Embodiments
[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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. Usually, the components of the embodiments of the present invention described and labeled in the accompanying drawings can be arranged and designed in various different configurations.
[0026] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.
[0027] It should be noted that similar reference numerals and letters indicate similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. In the description of the present invention, it should be noted that the terms "first", "second", "third", etc. are only used for descriptive distinction and cannot be understood as indicating or implying relative importance. The following will describe in detail some embodiments of the present invention with reference to the accompanying drawings. Without conflict, the following embodiments and the features in the embodiments can be combined with each other.
[0028] The method for customizing the interface timeout time provided by the present invention is mainly applicable to the timeout control scenario for implementing gateway technology, especially for the custom rewriting and passing of the timeout time of any specific interface under routing in Spring Cloud Gateway technology.
[0029] First Embodiment:
[0030] Figure 1 It is a schematic flowchart of the method for customizing the interface timeout time of the present invention. Refer to Figure 1, this embodiment provides a method for customizing the interface timeout time, including the following steps:
[0031] Step 1, when the gateway processes a request, create a rewritten timeout logic process that is preferentially executed in the process.
[0032] In this embodiment, the function of the rewritten timeout logic process is to write the changed parameters of the timeout time according to the needs of the designer or the feedback data of the gateway before matching the specific interface. Since interface matching is to be performed in the subsequent process, it should be preferentially executed.
[0033] Step 2, after the request enters the gateway, obtain the URI of the request and match it with the rewritten timeout logic process; if the match is successful, execute Step 3; if the match is unsuccessful, do not perform the operation of defining the timeout time for the interface.
[0034] In this embodiment, the URI in the request data is matched with the URI of the rewritten timeout logic process to determine the interface for which the timeout time is to be rewritten. If there is no match, no timeout time rewriting is performed for any interface.
[0035] Step 3, execute the rewritten timeout logic process, that is, based on the routing metadata of the interface with a successful match, the rewritten timeout logic process reconstructs new routing metadata and overwrites the original routing metadata.
[0036] In this embodiment, for the interface with a successful match, the routing configuration requested by the interface is retrieved from the request context according to the routing configuration Key, and a new routing configuration is reconstructed based on the routing configuration, mainly rewriting the timeout metadata configuration for covering the route. The new routing configuration is rewritten into the context of the request as the routing data of the current request, and the rewriting of the timeout time is completed. The subsequent process can fully reuse the logic process of the Gateway.
[0037] In the method for customizing the interface timeout time of the above embodiment, since the timeout parameter is rewritten before the interface request in the gateway, the setting and transmission of the timeout parameters for any interface under any route in the gateway are realized, ensuring that the overall routing timeout is not affected and solving the problem that all interfaces share one configuration. Through this method, the problem that specific interfaces with long consumption time are interrupted due to a short unified timeout time, resulting in users being unable to obtain data normally, can be solved.
[0038] Further, on the basis of the above embodiment, it is preferably to use a Pre-Filter filter to implement the preferential execution of the rewritten timeout logic process. At this time, the request is called before routing, and functions such as authentication, selecting the microservice of the request in the cluster, and recording debugging information can be implemented by using this filter. Since the call time is prior, it can ensure that the rewritten timeout logic process is located in the most front-end process.
[0039] Further, on the basis of the above embodiments, it is preferable to use a Pre-Filter to obtain the URI of the request. For the same reason as above, the Pre-Filter can obtain the URI of the request early, improving the efficiency of customizing the interface timeout time.
[0040] Further, on the basis of the above embodiments, the gateway configuration is added. The gateway is allowed to support multiple interfaces to add custom configuration timeout times simultaneously.
[0041] Further, on the basis of the above embodiments, it is preferable to construct an additional interface in the gateway. This additional interface can provide redundant configuration for the custom logic process of the interface timeout time, facilitating the dynamic addition of timeout configurations.
[0042] Further, on the basis of the above embodiments, it is preferable to load the rewritten timeout logic process into the server memory. This design can ensure that the rewritten timeout logic process responds in a timely manner in the case of multiple programs running, greatly improving the performance of configuration reading.
[0043] Second Embodiment:
[0044] Figure 2 This is a schematic structural diagram of the device for customizing the interface timeout time of the present invention. Please refer to Figure 2 In this embodiment, a device based on the above method for customizing the interface timeout time is provided. The device includes a processing module, and the processing module is used to call the rewritten timeout logic process, determine whether the URI of the request matches the rewritten timeout logic process, and execute the rewritten timeout logic process in the gateway.
[0045] In this embodiment, the device for customizing the interface timeout time can be set in the gateway or set independently and remotely connected to the gateway. Additionally, the data for customizing the interface timeout time can be designed according to the empirical values of processing requests, can be designed according to previous response data including parameters such as the number of timeout retries, the number of timeout failures, and the call duration, or a monitoring unit can be set to read the response data results of the gateway within a certain period of time and assign values by itself.
[0046] Further, on the basis of the above embodiments, the device for customizing the interface timeout time further includes a storage module for storing the rewritten timeout logic process. Similarly, setting the storage module independently in the device for customizing the interface timeout time can ensure that the device responds in a timely manner, greatly improving the performance of configuration reading.
[0047] Further, on the basis of the above embodiments, the interface timeout time customization device further includes a parsing module for obtaining the URI of the request. Independently setting the parsing module in the interface timeout time customization device can avoid interference with the program that reads the request URI in the case of multiple programs running.
[0048] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for customizing interface timeout time, characterized in that It includes the following steps: Step 1: When the gateway processes a request, create a rewrite timeout logic process that is preferentially executed in the process; Step 2: After the request enters the gateway, obtain the URI of the request and match it with the rewrite timeout logic process; if the match is successful, execute Step 3; if the match is unsuccessful, do not perform the operation of defining the timeout time for the interface; Step 3, execute the rewrite timeout logic process, that is, based on the routing metadata of the interface with a successful match, the rewrite timeout logic process reconstructs new routing metadata and overwrites the original routing metadata; Among them, for the interface with a successful match, the routing configuration requested by the interface is retrieved from the request context according to the routing configuration key, a routing configuration is rebuilt based on the routing configuration, the timeout metadata configuration for overwriting the routing is rewritten, and the new routing configuration is rewritten into the context of the request as the routing data of the current request, thus completing the rewriting of the timeout time, and its subsequent process can fully reuse the logic process of the gateway; Among them, the gateway configuration is increased to allow the gateway to support multiple interfaces to add custom configuration timeout times simultaneously.
2. The interface timeout time customization method according to claim 1, characterized in that, In Step 1, use the Pre-Filter filter to implement the preferential execution of the rewrite timeout logic process, increase the gateway configuration, build an additional interface in the gateway, and load the rewrite timeout logic process into the server memory.
3. The interface timeout time customization method according to claim 1, characterized in that, In Step 2, use the Pre-Filter filter to obtain the URI of the request.
4. An interface timeout time customizing device for the interface timeout time customizing method according to the above-mentioned claim 1, characterized in that, It includes a processing module, which is used to call the rewrite timeout logic process, to judge whether the URI of the request matches the rewrite timeout logic process, and to execute the rewrite timeout logic process in the gateway.
5. The interface timeout time customizing device according to claim 4, wherein It also includes a storage module for storing the rewrite timeout logic process and a parsing module for obtaining the URI of the request.
Citation Information
Patent Citations
Service execution method and device, computer equipment and storage medium
CN111580793A