Method, apparatus and electronic device for configuring read timeout
By dynamically configuring the read timeout on the configuration center device, the lack of flexibility in the existing technology is solved, enabling flexible modification of the HTTP interface read timeout and reducing maintenance costs.
Patent Information
- Application Number
- CN202410690597.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2044-05-30
AI Technical Summary
In existing technologies, the configuration method for read timeout is not very flexible, which leads to the need to modify code and redeploy, increasing the downtime and maintenance costs of the business server.
By intercepting the call request generated by RestTemplate, obtaining the target read timeout using the configuration center device, generating the target RequestConfig object, and replacing the original RequestConfig object, dynamic configuration of the read timeout for the HTTP interface can be achieved.
It improves the configuration flexibility of read timeout time and reduces downtime and maintenance costs for business servers.
Smart Images

Figure CN118433169B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer technology, and in particular, to a configuration method and device of read timeout time and electronic equipment. BACKGROUND
[0002] With the growth of business demand, a business service end usually connects multiple downstream service ends to improve the business capability that the business service end can provide by calling the downstream service ends. Among them, the downstream service ends can provide a Hypertext Transfer Protocol (HTTP) interface for the business service end to call to provide various functions for the business service end. RestTemplate is an HTTP request tool supported from Spring 3.0, which provides templates for common Representational State Transfer (REST) request schemes, such as GET request, POST request, PUT request, DELETE request, and some general request execution methods. The business service end can use RestTemplate to make HTTP request calls to the HTTP interface provided by each downstream service end to use the functions of the downstream service end.
[0003] Among them, when making an HTTP request call through RestTemplate, it is usually necessary to configure request key parameters such as the number of connections, connection timeout time, read timeout time, etc. The read timeout time refers to the maximum time for obtaining response data from the HTTP interface. However, the data processing capabilities of different downstream service ends may be different. Therefore, the time for different HTTP interfaces to return response data is different. Thus, it is necessary to separately configure the read timeout time for the HTTP interfaces of different downstream service ends.
[0004] However, the current way of configuring the read timeout time for each HTTP interface is usually to hardcode the read timeout time in the code of RestTemplate. This results in the need to modify the corresponding code if the read timeout time corresponding to the HTTP interface needs to be changed, and the modified code needs to be re-written and deployed so that the modified read timeout time is applied. This configuration method of read timeout time not only makes the configuration flexibility of the read timeout time poor, but also increases the downtime and maintenance cost of the business service end. SUMMARY
[0005] The embodiments of the present application aim to provide a configuration method and device of read timeout time and electronic equipment, which to some extent solve the problem of poor configuration flexibility of the current configuration method of read timeout time. The specific technical solutions are as follows:
[0006] In a first aspect of the present application, a configuration method of a read timeout time is provided, which is applied to a service device, and the method comprises:
[0007] intercepting a calling request generated by a RestTemplate for an HTTP interface of a downstream server, reading request parameters of the calling request, the request parameters at least comprising an interface name of the HTTP interface;
[0008] sending the request parameters to a configuration center device, so that the configuration center device acquires a target read timeout time corresponding to the request parameters;
[0009] receiving the target read timeout time sent by the configuration center device;
[0010] generating a target RequestConfig object according to the target read timeout time, wherein a value of a read timeout time parameter in the target RequestConfig object is the target read timeout time;
[0011] replacing a RequestConfig object in a ClientHttpRequest object of the calling request with the target RequestConfig object;
[0012] executing the calling request obtained after the replacement.
[0013] In a second aspect of the present application, a configuration method of a read timeout time is also provided, which is applied to a configuration center device, and the method comprises:
[0014] receiving request parameters of a calling request sent by a service device, the calling request being a calling request generated by a RestTemplate for an HTTP interface of a downstream server, the request parameters at least comprising an interface name of the HTTP interface;
[0015] acquiring a target read timeout time corresponding to the request parameters;
[0016] sending the target read timeout time to the service device.
[0017] In a third aspect of the present application, a configuration device of a read timeout time is also provided, which is arranged in a service device, and the device comprises:
[0018] an intercepting module, configured to intercept a calling request generated by a RestTemplate for an HTTP interface of a downstream server, read request parameters of the calling request, the request parameters at least comprising an interface name of the HTTP interface;
[0019] The sending module is configured to send the request parameter to the configuration center device, so that the configuration center device acquires a target read timeout corresponding to the request parameter;
[0020] The receiving module is configured to receive the target read timeout sent by the configuration center device.
[0021] The generating module is configured to generate a target RequestConfig object according to the target read timeout, wherein a value of a read timeout parameter in the target RequestConfig object is the target read timeout.
[0022] The replacing module is configured to replace a RequestConfig object in a ClientHttpRequest object of the calling request with the target RequestConfig object.
[0023] The executing module is configured to execute the calling request obtained after the replacement.
[0024] In the fourth aspect of the present application, a read timeout configuration device is also provided, which is arranged in a configuration center device, and comprises:
[0025] The receiving module is configured to receive a request parameter of a calling request sent by a business service device, wherein the calling request is a calling request generated by a RestTemplate for an HTTP interface of a downstream server, and the request parameter at least comprises an interface name of the HTTP interface.
[0026] The obtaining module is configured to obtain a target read timeout corresponding to the request parameter.
[0027] The sending module is configured to send the target read timeout to the business service device.
[0028] In the fifth aspect of the present application, an electronic device is also provided, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus.
[0029] The memory is configured to store a computer program.
[0030] The processor is configured to execute the program stored in the memory, so as to realize the method steps of any one of the first aspect or the second aspect.
[0031] In the sixth aspect of the present application, a computer readable storage medium is also provided, wherein instructions are stored in the computer readable storage medium, and when the instructions are run on a computer, the computer is caused to execute the read timeout configuration method of any one of the first aspect or the second aspect.
[0032] In a sixth aspect of the embodiments of the present application, a computer program product is further provided, which comprises a computer program, and the computer program, when executed by a processor, implements the method for configuring the read timeout time according to any one of the first aspect or the second aspect.
[0033] The method, device and electronic equipment for configuring the read timeout time provided by the embodiments of the present application can intercept the calling request generated by RestTemplate for the HTTP interface of the downstream server, read the target read timeout time corresponding to the request parameter of the calling request after reading the request parameter, and then generate a target RequestConfig object in which the value of the read timeout time parameter is the target read timeout time, through the configuration center device. Thus, the RequestConfig object in the ClientHttpRequest object of the calling request is replaced by the target RequestConfig object, so that the calling request obtained after the replacement is executed through the replaced ClientHttpRequest object.
[0034] In the technical solution, if the read timeout time corresponding to the HTTP interface needs to be changed, the new read timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout time, i.e., the target read timeout time, of the HTTP interface in the configuration center device after intercepting the calling request of the HTTP interface, and thus the read timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request is modified, so that the ClientHttpRequest object executes the calling request based on the new read timeout time, and the read timeout time of the calling request of the HTTP interface is modified. Compared with the related art, the read timeout time of the HTTP interface does not need to be modified by modifying the corresponding interface request code running on the business service device, which improves the configuration flexibility of the read timeout time of the HTTP interface, reduces the downtime and maintenance cost of the business service device. BRIEF DESCRIPTION OF DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced.
[0036] Figure 1 An implementation environment schematic diagram of a method for configuring a read timeout time provided by an embodiment of the present application;
[0037] Figure 2 A flowchart of a method for configuring a read timeout time provided by an embodiment of the present application;
[0038] Figure 3 A schematic diagram of a configuration method of a read timeout provided by an embodiment of the present application;
[0039] Figure 4 A flowchart of a configuration method of a read timeout provided by another embodiment of the present application;
[0040] Figure 5 A flowchart of a configuration method of a read timeout provided by another embodiment of the present application;
[0041] Figure 6 A block diagram of a configuration device of a read timeout provided by an embodiment of the present application;
[0042] Figure 7 A block diagram of another configuration device of a read timeout provided by an embodiment of the present application;
[0043] Figure 8 A structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0044] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings. In order to facilitate understanding, the following describes some terms related to the technical solutions of the present application.
[0045] Configuration center: a component capable of storing and managing the read timeout of the HTTP interface of each downstream service end.
[0046] RestTemplate: an HTTP request tool supported by Spring 3.0. It provides templates of common Representational State Transfer (REST) request schemes, such as GET request, POST request, PUT request, DELETE request, and some general request execution methods.
[0047] RequestConfig object: a class used to set the related parameters of the HTTP request sent by the Http client (HttpClient).
[0048] ClientHttpRequest object: a class used to encapsulate the related operation information of an HTTP request.
[0049] ClientHttpRequestFactory object: a class for creating a ClientHttpRequest object and setting related parameters of the HttpClient.
[0050] HttpClient object: a class for executing an HTTP request and processing an HTTP response.
[0051] HttpUriRequest object: a class for representing an HTTP request.
[0052] The HttpClient object is used to send an HTTP request represented by an HttpUriRequest object to an Http server (HttpServer) through a ClientHttpRequest object with related parameters set by a RequestConfig object.
[0053] Please refer to Figure 1 , which shows an implementation environment of a configuration method for reading a timeout time according to an embodiment of the present application. As shown in Figure 1 , the implementation environment 10 includes a business service device 101 and a configuration center device 102.
[0054] The business service device 101 and the configuration center device 102 can be connected through a network. Alternatively, the business service device 101 and the configuration center device 102 can be connected through a wireless network. The wireless network 102 can be a Wireless Local Area Network (WLAN), a Wireless Wide Area Network (WWAN), a Wireless Metropolitan Area Network (WMAN), and a Wireless Personal Area Network (WPAN). The WLAN can include a network that provides wireless communication access within a short distance, such as a Wi-Fi network. The WWAN can include a wireless communication network based on a mobile communication infrastructure, such as a 2G / 3G / 4G / 5G wireless network. The WMAN allows access users to access a wireless network in a fixed place, which connects multiple fixed places in a city or region. The WPAN is a wireless network in which a user connects portable devices owned by the user through a communication device for a short distance.
[0055] The business service device 101 is configured to invoke the service provided by the downstream service end by generating a calling request of the HTTP interface of the downstream service end. The calling request of the HTTP interface is also referred to as an HTTP request. Alternatively, the business service device 101 can be a terminal such as a mobile phone, a personal computer, a tablet computer, a wearable device, or a device such as a server or a cloud service cluster.
[0056] The configuration center device 102 is configured to run a configuration center component. The configuration center component can be used to at least manage the read timeout of the HTTP interface of each downstream service end. The manager can configure the read timeout of the HTTP interface of each downstream service end on the configuration center component, so that the business service device 101 reads and applies the configured read timeout from the configuration center component. Alternatively, the configuration center component can be a Zookeeper, a Nacos, an Apollo, or the like. Further alternatively, the configuration center device 102 can be a terminal such as a mobile phone, a personal computer, a tablet computer, a wearable device, or a device such as a server or a cloud service cluster.
[0057] Please refer to Figure 2 , which shows a flowchart of a read timeout configuration method provided by an embodiment of the present application. The read timeout configuration method can be applied to the implementation environment shown in Figure 1 , as shown in Figure 2 , the read timeout configuration method comprises the following steps.
[0058] In step 201, the business service device intercepts a calling request generated by RestTemplate for the HTTP interface of the downstream service end, and reads the request parameters of the calling request.
[0059] When the business service device needs to call the data of the downstream service end, the business service device can generate a calling request for the downstream service end through RestTemplate, and send the calling request to the downstream service end, so as to obtain the data provided by the downstream service end. In the embodiment of the present application, the business service device can intercept the calling request generated by RestTemplate for the HTTP interface of the downstream service end, so as to modify the read timeout of the calling request by executing the subsequent steps.
[0060] The calling request is used to request the data provided by the HTTP interface of the downstream service end. The request parameters at least include the interface name of the HTTP interface. Alternatively, the business service device can parse the request parameters of the calling request after intercepting the calling method generated by RestTemplate.
[0061] In some embodiments of the present application, the business service device can invoke an interceptor to intercept a calling request generated by the RestTemplate for the HTTP interface of the downstream server. The interceptor is configured to perform a process required before the calling request is executed. That is, the interceptor is configured to cause the business service device to perform a step of modifying the read timeout of the calling request before the calling request generated by the RestTemplate is executed. It can be understood that the interceptor is configured to, when detecting the calling request generated by the RestTemplate, cause the business service device to not execute the calling request first, but to perform a step of modifying the read timeout of the calling request, and then execute the modified calling request. The step of modifying the read timeout of the calling request can be steps 202 to 205.
[0062] Based on this, before the business service device performs step 201 to intercept the calling request generated by the RestTemplate for the HTTP interface of the downstream server, the business service device can also create an interceptor suitable for the RestTemplate.
[0063] In an optional implementation, the process of creating the interceptor suitable for the RestTemplate by the business service device can include defining the interceptor and registering the interceptor with the RestTemplate.
[0064] The interceptor is configured to create a class that implements a ClientHttpRequestInterceptor interface. The ClientHttpRequestInterceptor interface is configured to call a first method. The first method is configured to cause the business service device to perform a step of modifying the read timeout of the calling request before the calling request generated by the RestTemplate is executed. Specifically, the first method is configured to cause the business service device to perform steps 202 to 205 before the calling request generated by the RestTemplate is executed. For example, the first method can be an intercept method. The intercept method is configured to cause the business service device to perform a step of modifying the read timeout of the calling request before the calling request generated by the RestTemplate is executed.
[0065] Further optionally, the business service device can call a RestTemplate registration method to register the defined interceptor to the RestTemplate. For example, the RestTemplate registration method can be a setInterceptors method provided by the RestTemplate. The business service device adds the interceptor to a resource list List<> of the RestTemplate by calling the setInterceptors method, so as to register the interceptor in the RestTemplate. For another example, the RestTemplate registration method can be a @Bean annotation method. The interceptor is added to the RestTemplate by the @Bean annotation.
[0066] Step 202, the business service device sends a request parameter to the configuration center device.
[0067] In the embodiment, the business service device sends the request parameter to the configuration center device through a connection network between the business service device and the configuration center device.
[0068] Step 203, the configuration center device acquires a target read timeout corresponding to the request parameter.
[0069] In the embodiment, the configuration center device can store a target correspondence relationship between an interface name of an HTTP interface of each downstream service end of the business service device and a read timeout. After receiving the request parameter sent by the business service device, the configuration center device can acquire the target correspondence relationship, and determine a target read timeout corresponding to the interface name in the request parameter according to the target correspondence relationship.
[0070] In an optional case, the target correspondence relationship stored by the configuration center device can be a correspondence relationship between the interface name and a numerical value of the read timeout. That is, the configuration center device stores a specific numerical value of the read timeout corresponding to the HTTP interface.
[0071] Based on this, the process that the configuration center device acquires the target read timeout corresponding to the request parameter can include: the configuration center device acquires a correspondence relationship between an interface name of an HTTP interface of each downstream service end of the business service device and a read timeout, and determines a target read timeout corresponding to the interface name in the request parameter according to the correspondence relationship.
[0072] It should be noted that the read timeout time corresponding to the HTTP interface stored by the configuration center device can be custom configured data. For example, the read timeout time corresponding to the HTTP interface can be configured manually according to the interface demand and performance of the HTTP interface. Alternatively, the read timeout time corresponding to the HTTP interface can be automatically generated according to the historical read timeout time of the HTTP interface. For example, the configuration center device can automatically configure the average or mode of a plurality of historical read timeout times of the HTTP interface as the read timeout time of the HTTP interface in the target correspondence.
[0073] For example, the configuration center device records the target correspondence in the form of a key-value pair. The key field in the key-value pair is used to store the interface name, and the value field is used to store the corresponding read timeout time. For example, the configuration center device stores a first key-value pair to a third key-value pair. The first key-value pair: the interface name of the first HTTP interface of the first downstream server-read timeout time 2 seconds (s). The second key-value pair: the interface name of the second HTTP interface of the first downstream server-read timeout time 1 s. The third key-value pair: the interface name of the first HTTP interface of the second downstream server-read timeout time 1.5 s.
[0074] In another optional case, the target correspondence stored by the configuration center device can be the correspondence between the interface name and the reference algorithm of the read timeout time. That is, the configuration center stores the calculation method of the read timeout time corresponding to the HTTP interface. The reference algorithm is used to calculate the read timeout time of the corresponding HTTP interface.
[0075] The reference algorithm corresponding to the HTTP interface of the plurality of downstream servers can be at least partially the same, or can be at least partially different. It should be noted that the reference algorithm corresponding to each HTTP interface can be an algorithm that is custom configured by the administrator from a preset algorithm according to the business demand corresponding to the HTTP interface. The reference algorithm of the HTTP interface can also be an algorithm that is defined by the administrator according to the business demand of the HTTP interface.
[0076] For example, the configuration center device can display an algorithm editing interface in response to an algorithm editing instruction of the HTTP interface, determine a calculation expression input in the algorithm editing interface as a parameter algorithm of the HTTP interface, and configure the parameter algorithm to the target correspondence. For example, after an administrator inputs an interface name of the HTTP interface, the administrator clicks an algorithm editing control to cause the configuration center device to generate an algorithm editing instruction of the HTTP interface in response to the click input of the algorithm editing control, and display the algorithm editing interface. The administrator writes a calculation expression of a read timeout time of the HTTP interface in the algorithm editing interface to cause the configuration center device to determine the calculation expression as a parameter algorithm of the HTTP interface, and configure the parameter algorithm to the target correspondence.
[0077] For another example, the configuration center device records the target correspondence in a key-value pair. A key field of the key-value pair is used to store an interface name, and a value field is used to store a corresponding reference algorithm. For example, the configuration center device stores a first key-value pair to a third key-value pair. The first key-value pair is a first interface name-first reference algorithm. The second key-value pair is a second interface name-second reference algorithm. The third key-value pair is a third interface name-third reference algorithm. The first interface name is a name of a first HTTP interface of a first downstream service end. The second interface name is a name of a second HTTP interface of the first downstream service end. The third interface name is a name of a first HTTP interface of a second downstream service end.
[0078] After receiving a request parameter of a service request sent by the service device, the configuration center device searches for a second reference algorithm corresponding to the second interface name in the target correspondence, and calculates a target read timeout time corresponding to the second interface name by using the second parameter algorithm.
[0079] In this way, different reference algorithms are configured for different HTTP interfaces on the configuration center device, so that the read timeout time of each HTTP interface can be generated more flexibly. Compared with a method of directly configuring a fixed numerical read timeout time for an HTTP interface, the reference algorithm is configured, so that a more accurate read timeout time of the HTTP interface can be calculated in real time according to the reference algorithm corresponding to the HTTP interface, and the configuration accuracy of the read timeout time of the HTTP interface is effectively ensured.
[0080] Optionally, the request parameter of the calling request can further include a plurality of related parameters of the calling request. The values of the related parameters affect the response rate of the HTTP interface. For example, the related parameters can include at least one of a request number, a request time, a request path, and request header data. For example, the related parameters include the request number, the request time, the request path, and the request header data.
[0081] The request times refer to the number of calling requests generated by the business service device through the RestTemplate for the HTTP interface of the downstream server in a target historical period. For example, the target historical period is the previous month, the previous three months, etc. The request time refers to the time of the calling request generated by the business service device for the HTTP interface of the downstream server. The request path can refer to the path of the business service device requesting to access the downstream server.
[0082] Correspondingly, the reference algorithm of the HTTP interface can be used to calculate the reading timeout time of the corresponding HTTP interface according to a plurality of related parameters of the calling request. Based on this, the process that the configuration center device acquires the target reading timeout time corresponding to the request parameter can include: the configuration center device acquires the reference algorithm corresponding to the interface name, and calculates the target reading timeout time by using the reference algorithm according to a plurality of related parameters. For example, the reference algorithm can be an EMA timeout algorithm, a DMA timeout algorithm, etc.
[0083] Step 204, the configuration center device sends the target reading timeout time to the business service device.
[0084] In the embodiment of the application, the configuration center device sends the target reading timeout time corresponding to the HTTP interface to the business service device through the connection network between the configuration center device and the business service device.
[0085] Step 205, the business service device generates a target RequestConfig object according to the target reading timeout time. The value of the reading timeout time parameter in the target RequestConfig object is the target reading timeout time.
[0086] In the embodiment of the application, the business service device can generate the target RequestConfig object after receiving the target reading timeout time sent by the configuration center device. In this way, the business service device can convert the reading timeout time configured for the HTTP interface into the RequestConfig object for execution.
[0087] In an optional implementation manner, the business service device can call the RequestConfig object of the calling request, modify the reading timeout time parameter in the RequestConfig object to the target reading timeout time, and obtain the target RequestConfig object.
[0088] For example, the business service device can obtain a ClientHttpRequest object of the calling request. The business service device can call a getRequestFactory method of the ClientHttpRequest object to obtain a ClientHttpRequestFactory object of the calling request. Then, the business service device can call a getHttpClient method of the ClientHttpRequestFactory object to obtain an HttpClient object of the calling request. Further, the business service device can call an execute method of the HttpClient object to obtain an HttpUriRequest object of the calling request, and call a getConfig method of the HttpUriRequest object to obtain a RequestConfig object currently used by the calling request. The business service device can modify a value of a read timeout parameter in the RequestConfig object to a target read timeout, and obtain a target RequestConfig object.
[0089] In another optional implementation, the business service device can also directly generate a new RequestConfig object, set a read timeout parameter in the new RequestConfig object to the target read timeout, and call an original RequestConfig object of the calling request. The business service device can copy values of other parameters in the original RequestConfig object to the new RequestConfig object, and obtain the target RequestConfig object. The other parameters refer to parameters in the RequestConfig object except the read timeout parameter.
[0090] Further optionally, the business service device can call a fourth method to generate a new RequestConfig object of the calling request, and call a fifth method to set a read timeout parameter in the new RequestConfig object to the target read timeout. For example, the fourth method is also referred to as a RequestConfig object generation method, which can be a RequestConfig.custom method. The fifth method is also referred to as a parameter configuration method, which can be a setSocketTimeout method.
[0091] It is understandable that the target RequestConfig object generated in this way is different from the original RequestConfig object only in the read timeout parameter. Of course, other parameters in the target RequestConfig object can also be updated. For example, the configuration center device can also store the target parameter values corresponding to the HTTP interface. The target parameter value is the value of the target parameter in the RequestConfig object of the calling request of the HTTP interface. The target parameter is a parameter in the target RequestConfig object except the read timeout parameter.
[0092] Step 206, the service service device replaces the RequestConfig object in the ClientHttpRequest object of the calling request with the target RequestConfig object.
[0093] In the embodiment of the application, the service service device replaces the RequestConfig object in the ClientHttpRequest object of the calling request with the target RequestConfig object, so as to execute the calling request by using the related parameters of the target RequestConfig object through the ClientHttpRequest object.
[0094] Optionally, the process that the service service device replaces the RequestConfig object in the ClientHttpRequest object of the calling request with the target RequestConfig object can include: obtaining the ClientHttpRequest object of the calling request. A second method is called to obtain the HttpUriRequest object in the ClientHttpRequest object. A third method is called to configure the target RequestConfig object to the HttpUriRequest object, and replace the RequestConfig object in the HttpUriRequest object.
[0095] The second method is used to obtain the HttpClient object by obtaining the ClientHttpRequestFactory object currently used by the ClientHttpRequest object, and then obtain the HttpUriRequest object through the HttpClient object. The third method is used to cover the RequestConfig object in the HttpUriRequest object with the target RequestConfig object, so as to replace the RequestConfig object in the HttpUriRequest object.
[0096] For example, the second method can include a getRequestFactory method of the ClientHttpRequest object and a getHttpClient method of the ClientHttpRequestFactory object. The third method can include an execute method of the HttpClient object and a setConfig method of the HttpUriRequest object.
[0097] Based on this, the business service device can obtain the ClientHttpRequest object of the calling request, call the getRequestFactory method of the ClientHttpRequest object to obtain the ClientHttpRequestFactory object of the calling request. Then, the getHttpClient method of the ClientHttpRequestFactory object is called to obtain the HttpClient object of the calling request. Further, the execute method of the HttpClient object is called to obtain the HttpUriRequest object of the calling request. The setConfig method of the HttpUriRequest object is called to configure the target RequestConfig object into the HttpUriRequest object, replacing the RequestConfig object in the HttpUriRequest object.
[0098] Step 207, the business service device executes the calling request obtained after replacement.
[0099] In the embodiment of the application, the business service device executes the calling request obtained after replacement to send the calling request obtained after replacement to the HTTP interface of the downstream service device, and waits for the interface response of the HTTP interface. If the business service device receives the interface response of the HTTP interface within the target reading timeout, the business service device continues to process the interface response. If the business service device does not receive the interface response of the HTTP interface within the target reading timeout, the business service device outputs an HTTP interface response exception.
[0100] For example, when the business service device receives a data request of an upstream request device, the business service device indicates that the data of the downstream service device needs to be called, and generates a calling request of the downstream service device. The business service device executes the calling request. If the business service device receives the interface response of the HTTP interface within the target reading timeout, the business service device returns the interface response to the upstream request device. If the business service device does not receive the interface response of the HTTP interface within the target reading timeout, the business service device outputs and transmits an HTTP interface response exception to the upstream request device, so that the upstream request device processes the exception.
[0101] In the embodiment of the present application, by intercepting the calling request generated by RestTemplate for the HTTP interface of the downstream server, after reading the request parameters of the calling request, the target read timeout time corresponding to the request parameters is read through the configuration center device, and then a target RequestConfig object whose read timeout time parameter value is the target read timeout time is generated. Thus, the RequestConfig object in the ClientHttpRequest object of the calling request is replaced with the target RequestConfig object, so as to execute the calling request obtained after the replacement through the replaced ClientHttpRequest object.
[0102] In the technical solution, if it is necessary to change the read timeout time corresponding to the HTTP interface, the new read timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout time, i.e., the target read timeout time, of the HTTP interface in the configuration center device after intercepting the calling request of the HTTP interface, thereby modifying the read timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request, so that the ClientHttpRequest object executes the calling request based on the new read timeout time, and the modification of the read timeout time of the calling request of the HTTP interface is realized. Compared with the related art, it is not necessary to modify the corresponding interface request code running on the business service device to modify the read timeout time of the HTTP interface, which improves the configuration flexibility of the read timeout time of the HTTP interface and reduces the downtime and maintenance cost of the business service device.
[0103] For ease of understanding, the configuration method of the read timeout time provided by the embodiment of the present application is further described below with an example. Please refer to Figure 3 which shows the principle diagram of the configuration method of the read timeout time provided by the embodiment of the present application. As shown in Figure 3 , the configuration method comprises:
[0104] The user device (User) sets the read timeout time configuration item for each HTTP interface (i.e., downstream interface) of the downstream service device on the configuration center component through the configuration center device, so as to configure the read timeout time for each HTTP interface. The configuration item of each HTTP interface on the configuration center component can be set according to the interface demand and performance of the HTTP interface to meet the different configuration demands of different HTTP interfaces for the read timeout time. The configuration center component is used to configure the personalized read request time for each HTTP interface request.
[0105] The user equipment responds to the interceptor definition operation, so that the business service equipment creates an interceptor (i.e., RestTemplate Interceptor) and registers the interceptor with the RestTemplate to intercept the call request generated by the RestTemplate for the HTTP interface of the downstream service end. The interceptor is used to modify the request-related data before each call request execution, that is, the interceptor is used to perform the step of modifying the read timeout of the call request before each call request execution.
[0106] The interceptor intercepts the call request generated by the RestTemplate for the HTTP interface of the downstream service end, reads the request parameters of the call request, and then obtains the target read timeout corresponding to the current call request from the configuration center component. The interceptor generates a target RequestConfig object according to the target read timeout, to convert the target read timeout configured for the HTTP interface into a RequestConfig object, for executing the target read timeout.
[0107] The interceptor replaces the RequestConfig object in the ClientHttpRequest object of the call request with the target RequestConfig object, to execute the call request through the replaced ClientHttpRequest object. The business service equipment executes the call request to send the call request to the HTTP interface of the downstream service equipment, and waits for the interface response of the HTTP interface. If the business service equipment receives the interface response of the HTTP interface for the HttpUriRequest object within the target read timeout, the interface response is returned to the upstream request equipment. If the interface response of the HTTP interface for the HttpUriRequest object is not received within the target read timeout, an HTTP interface response exception is output and transmitted to the upstream request equipment, for processing the exception by the upstream request equipment.
[0108] In summary, the configuration method of the read timeout provided by the embodiments of the present application intercepts the call request generated by the RestTemplate for the HTTP interface of the downstream service end, to read the target read timeout corresponding to the request parameters through the configuration center equipment after reading the request parameters of the call request, and then generate a target RequestConfig object with the target read timeout as the value of the read timeout parameter. The RequestConfig object in the ClientHttpRequest object of the call request is replaced with the target RequestConfig object, to execute the call request obtained after the replacement through the replaced ClientHttpRequest object.
[0109] In the technical solution, if the read timeout time corresponding to the HTTP interface needs to be changed, the new read timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout time of the HTTP interface configured in the configuration center device as the target read timeout time after intercepting the calling request of the HTTP interface, and modifies the read timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request, so that the ClientHttpRequest object executes the calling request based on the new read timeout time, and the read timeout time of the calling request of the HTTP interface is modified. Compared with the related art, the read timeout time of the HTTP interface is modified without modifying the corresponding interface request code running on the business service device, the configuration flexibility of the read timeout time of the HTTP interface is improved, and the downtime and maintenance cost of the business service end are reduced.
[0110] Please refer to Figure 4 which shows a flowchart of a read timeout time configuration method provided by an embodiment of the application. The configuration method is applied to Figure 1 the implementation environment shown in the figure, and is executed by a business service device. As Figure 4 shown, the read timeout time configuration method comprises the following steps.
[0111] Step 401: Intercept a calling request generated by RestTemplate for an HTTP interface of a downstream server, read request parameters of the calling request, and the request parameters at least include an interface name of the HTTP interface.
[0112] Step 402: Send the request parameters to a configuration center device, so that the configuration center device obtains a target read timeout time corresponding to the request parameters.
[0113] Step 403: Receive the target read timeout time sent by the configuration center device.
[0114] Step 404: Generate a target RequestConfig object according to the target read timeout time, and the value of the read timeout time parameter in the target RequestConfig object is the target read timeout time.
[0115] Step 405: Replace the RequestConfig object in the ClientHttpRequest object of the calling request with the target RequestConfig object.
[0116] Step 406: Execute the calling request obtained after the replacement.
[0117] The explanation and implementation of steps 401 to 404 can refer to the explanation and implementation of the related steps performed by the business service device in the foregoing embodiments, and the present embodiment will not repeat the same.
[0118] Optionally, before intercepting the invocation request generated by the RestTemplate for the HTTP interface of the downstream server, the method further comprises:
[0119] defining an interceptor, the interceptor being configured to create a class implementing a ClientHttpRequestInterceptor interface, the ClientHttpRequestInterceptor interface being configured to call a first method, the first method being configured to perform the step of sending the request parameter to the configuration center device before the business service device executes the invocation request generated by the RestTemplate, to the step of replacing the RequestConfig object in the ClientHttpRequest object of the invocation request with the target RequestConfig object;
[0120] registering the interceptor with the RestTemplate;
[0121] intercepting the invocation request generated by the RestTemplate for the HTTP interface of the downstream server, comprising: calling the interceptor to intercept the invocation request generated by the RestTemplate for the HTTP interface of the downstream server.
[0122] Optionally, replacing the RequestConfig object in the ClientHttpRequest object of the invocation request with the target RequestConfig object comprises:
[0123] obtaining the ClientHttpRequest object of the invocation request;
[0124] calling a second method to obtain the HttpUriRequest object in the ClientHttpRequest object;
[0125] calling a third method to configure the target RequestConfig object to the HttpUriRequest object, to replace the RequestConfig object in the HttpUriRequest object.
[0126] Optionally, generating the RequestConfig object according to the target read timeout comprises:
[0127] calling a fourth method to generate the RequestConfig object of the invocation request;
[0128] The fifth method is called to set the read timeout parameter in the RequestConfig object to the target read timeout.
[0129] The explanation and implementation of each step in this embodiment can refer to the explanation and implementation of the related steps performed by the business service device in the foregoing embodiments, which will not be repeated here.
[0130] In summary, the configuration method of the read timeout provided in the embodiments of this application intercepts the calling request generated by RestTemplate for the HTTP interface of the downstream service end, reads the target read timeout corresponding to the request parameter of the calling request after the request parameter, and then reads the target read timeout corresponding to the request parameter through the configuration center device, and generates a target RequestConfig object with the read timeout parameter value of the target read timeout. The RequestConfig object in the ClientHttpRequest object of the calling request is replaced with the target RequestConfig object, and the calling request obtained after the replacement is executed through the replaced ClientHttpRequest object.
[0131] In this technical solution, if the read timeout corresponding to the HTTP interface needs to be changed, the new read timeout of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout, i.e., the target read timeout, of the HTTP interface in the configuration center device after intercepting the calling request of the HTTP interface, and then modifies the read timeout parameter of the RequestConfig object in the ClientHttpRequest object of the calling request, so that the ClientHttpRequest object executes the calling request based on the new read timeout, and the read timeout of the calling request of the HTTP interface is modified. Compared with the related art, it is not necessary to modify the corresponding interface request code running on the business service device to modify the read timeout of the HTTP interface, which improves the configuration flexibility of the read timeout of the HTTP interface, reduces the downtime and maintenance cost of the business service end.
[0132] Please refer to Figure 5 which shows a flowchart of a configuration method of a read timeout provided in an embodiment of this application. The configuration method is applied to Figure 1 and is executed by a configuration center device. As shown in Figure 5 , the configuration method of the read timeout includes:
[0133] Step 501, receiving a request parameter of a calling request sent by the business service device, the calling request being a calling request generated by a RestTemplate for an HTTP interface of a downstream server, and the request parameter at least including an interface name of the HTTP interface.
[0134] Step 502, obtaining a target read timeout corresponding to the request parameter.
[0135] Step 503, sending the target read timeout to the business service device.
[0136] The explanation and implementation mode of steps 501 to 503 can refer to the explanation and implementation mode of the related steps performed by the configuration center device in the foregoing embodiments, and the present embodiment will not repeat the explanation.
[0137] Optionally, obtaining the target read timeout corresponding to the request parameter includes: obtaining a corresponding relationship between the interface name of the HTTP interface of each downstream server of the business service device and the read timeout, and determining the target read timeout corresponding to the interface name in the request parameter according to the corresponding relationship.
[0138] Alternatively,
[0139] The request parameter further includes: a plurality of related parameters of the calling request, and obtaining the target read timeout corresponding to the request parameter includes: obtaining a reference algorithm corresponding to the interface name in the request parameter, and calculating the target read timeout by using the reference algorithm according to the plurality of related parameters.
[0140] Optionally, the related parameters include at least one of the following: a request number, a request time, a request path, and request header data.
[0141] The explanation and implementation mode of each step in the present embodiment can refer to the explanation and implementation mode of the related steps performed by the configuration center device in the foregoing embodiments, and the present embodiment will not repeat the explanation.
[0142] In summary, the configuration method of the read timeout provided in the present embodiment includes: intercepting a calling request generated by a RestTemplate for an HTTP interface of a downstream server, so as to read, after reading a request parameter of the calling request, a target read timeout corresponding to the request parameter by a configuration center device, and then generate a target RequestConfig object in which the value of a read timeout parameter is the target read timeout. Thus, the RequestConfig object in a ClientHttpRequest object of the calling request is replaced by the target RequestConfig object, so as to execute the calling request obtained after the replacement by using the ClientHttpRequest object after the replacement.
[0143] In the technical solution, if the read timeout time corresponding to the HTTP interface needs to be changed, the new read timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout time of the HTTP interface configured in the configuration center device as the target read timeout time after intercepting the calling request of the HTTP interface, and modifies the read timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request, so that the ClientHttpRequest object executes the calling request based on the new read timeout time, and the read timeout time of the calling request of the HTTP interface is modified. Compared with the related art, the read timeout time of the HTTP interface is modified without modifying the corresponding interface request code running on the business service device, the configuration flexibility of the read timeout time of the HTTP interface is improved, and the downtime and maintenance cost of the business service end are reduced.
[0144] Please refer to Figure 6 which shows a block diagram of a read timeout time configuration device provided by an embodiment of the application. As Figure 6 shown, the read timeout time configuration device 600 includes an intercepting module 601, a sending module 602, a receiving module 603, a generating module 604, a replacing module 605, and an executing module 606.
[0145] The intercepting module 601 is configured to intercept a calling request generated by a RestTemplate for an HTTP interface of a downstream service end, read request parameters of the calling request, and the request parameters at least include an interface name of the HTTP interface.
[0146] The sending module 602 is configured to send the request parameters to a configuration center device, so that the configuration center device obtains a target read timeout time corresponding to the request parameters.
[0147] The receiving module 603 is configured to receive the target read timeout time sent by the configuration center device.
[0148] The generating module 604 is configured to generate a target RequestConfig object according to the target read timeout time, and the value of the read timeout time parameter in the target RequestConfig object is the target read timeout time.
[0149] The replacing module 605 is configured to replace a RequestConfig object in a ClientHttpRequest object of the calling request with the target RequestConfig object.
[0150] The executing module 606 is configured to execute the calling request obtained after the replacement.
[0151] Optionally, the configuration device 600 for reading the timeout time further comprises a creating module and a registering module.
[0152] The creating module is configured to define an interceptor, the interceptor is configured to create a class implementing a ClientHttpRequestInterceptor interface, the ClientHttpRequestInterceptor interface is configured to call a first method, the first method is configured to perform a step of sending a request parameter to the configuration center device before the business service device executes a calling request generated by the RestTemplate, to a step of replacing a RequestConfig object in a ClientHttpRequest object of the calling request with a target RequestConfig object;
[0153] The registering module is configured to register the interceptor to the RestTemplate;
[0154] The intercepting module 601 is further configured to call the interceptor to intercept a calling request generated by the RestTemplate for an HTTP interface of a downstream service end.
[0155] Optionally, the replacing module 605 is further configured to:
[0156] obtain a ClientHttpRequest object of the calling request;
[0157] call a second method to obtain an HttpUriRequest object in the ClientHttpRequest object;
[0158] call a third method to configure the target RequestConfig object to the HttpUriRequest object, and replace a RequestConfig object in the HttpUriRequest object.
[0159] Optionally, the generating module 604 is further configured to:
[0160] call a fourth method to generate a RequestConfig object of the calling request;
[0161] call a fifth method to set a reading timeout time parameter in the RequestConfig object as the target reading timeout time.
[0162] In summary, the configuration device for reading timeout time provided by the embodiment of the application reads the target reading timeout time corresponding to the request parameter through the configuration center device after reading the request parameter of the calling request generated by RestTemplate for the HTTP interface of the downstream server, and then generates a target RequestConfig object with the value of the reading timeout time parameter being the target reading timeout time. Thus, the RequestConfig object in the ClientHttpRequest object of the calling request is replaced by the target RequestConfig object, so that the calling request obtained by replacing the ClientHttpRequest object is executed through the replaced ClientHttpRequest object.
[0163] In the technical solution, if the reading timeout time corresponding to the HTTP interface needs to be changed, the new reading timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new reading timeout time, i.e., the target reading timeout time, of the HTTP interface in the configuration center device after intercepting the calling request of the HTTP interface, and thus the reading timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request is modified, so that the ClientHttpRequest object executes the calling request based on the new reading timeout time, and the reading timeout time of the calling request of the HTTP interface is modified. Compared with the related art, the reading timeout time of the HTTP interface does not need to be modified by modifying the corresponding interface request code running on the business service device, the configuration flexibility of the reading timeout time of the HTTP interface is improved, and the downtime and maintenance cost of the business service device are reduced.
[0164] Please refer to Figure 7 which shows a block diagram of another configuration device for reading timeout time provided by the embodiment of the application. As Figure 7 shown, the configuration device for reading timeout time 700 includes a receiving module 701, an obtaining module 702, and a sending module 703.
[0165] The receiving module 701 is configured to receive the request parameter of the calling request sent by the business service device, the calling request being the calling request generated by RestTemplate for the HTTP interface of the downstream server, and the request parameter including at least the interface name of the HTTP interface.
[0166] The obtaining module 702 is configured to obtain the target reading timeout time corresponding to the request parameter.
[0167] The sending module 703 is configured to send the target reading timeout time to the business service device.
[0168] Optionally, the obtaining module 702 is further configured to obtain a preset read timeout time corresponding to the request parameter, to obtain the target read timeout time.
[0169] Alternatively, the request parameter further includes a plurality of related parameters of the calling request, and the obtaining module 702 is further configured to obtain a reference algorithm corresponding to the interface name, and calculate the target read timeout time by using the reference algorithm according to the plurality of related parameters.
[0170] Optionally, the obtaining module 702 is further configured to obtain a correspondence between an interface name and a read timeout time of an HTTP interface of each downstream service end of the business service device, and determine the target read timeout time corresponding to the interface name in the request parameter according to the correspondence.
[0171] Alternatively, the request parameter further includes a plurality of related parameters of the calling request. Optionally, the obtaining module 702 is further configured to obtain a reference algorithm corresponding to the interface name in the request parameter, and calculate the target read timeout time by using the reference algorithm according to the plurality of related parameters.
[0172] Optionally, the related parameters include at least one of the following: request times, request time, request path, and request header data.
[0173] In summary, the configuration device of the read timeout time provided by the embodiments of the present application intercepts the calling request generated by RestTemplate for the HTTP interface of the downstream service end, reads the target read timeout time corresponding to the request parameter of the calling request through the configuration center device after the request parameter, and then generates the target RequestConfig object of which the value of the read timeout time parameter is the target read timeout time. The RequestConfig object in the ClientHttpRequest object of the calling request is replaced by the target RequestConfig object, so as to execute the calling request obtained after the replacement through the replaced ClientHttpRequest object.
[0174] In the technical solution, if the read timeout time corresponding to the HTTP interface needs to be changed, the new read timeout time of the HTTP interface can be directly edited on the configuration center device, so that the business service device reads the new read timeout time of the HTTP interface, that is, the target read timeout time, after intercepting the calling request of the HTTP interface, and modifies the read timeout time parameter of the RequestConfig object in the ClientHttpRequest object of the calling request, so that the ClientHttpRequest object executes the calling request based on the new read timeout time, thereby achieving modification of the read timeout time of the calling request of the HTTP interface. Compared with the related art, the read timeout time of the HTTP interface does not need to be modified by modifying the corresponding interface request code running on the business service device, thereby improving the configuration flexibility of the read timeout time of the HTTP interface, reducing the downtime and maintenance cost of the business service end.
[0175] The embodiments of the present application also provide an electronic device, which can be the terminal or the server. Figure 8 As shown in the figure, the electronic device includes a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802 and the memory 803 complete mutual communication through the communication bus 804,
[0176] The memory 803 is configured to store a computer program.
[0177] The processor 801 is configured to execute the program stored in the memory 803, and implement the read timeout time configuration method provided by any of the embodiments of the present application.
[0178] The communication bus mentioned in the above electronic device can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.
[0179] The communication interface 604 is configured to communicate between the electronic device and other devices.
[0180] The memory can include a random access memory (RAM) and can also include a non-volatile memory such as at least one disk memory. Optionally, the memory can also be at least one storage device located remotely from the aforementioned processor.
[0181] The processor described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc. It can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
[0182] In yet another embodiment provided by the present application, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. When the computer program is executed by a processor of a terminal, the steps performed by a service device in the configuration method of the read timeout time according to any one of the above embodiments are implemented. Alternatively, when the computer program is executed by a processor of a server, the steps performed by a configuration center device in the configuration method of the read timeout time according to any one of the above embodiments are implemented.
[0183] In yet another embodiment provided by the present application, a computer program product is provided, and the computer program product includes a computer program. When the computer program is executed by a processor, the steps performed by a service device in the configuration method of the read timeout time according to any one of the above embodiments are implemented. Alternatively, when the computer program is executed by a processor of a server, the steps performed by a configuration center device in the configuration method of the read timeout time according to any one of the above embodiments are implemented.
[0184] In the embodiments described above, all or some of the steps can be implemented by hardware, software, firmware or any combination thereof. When implemented in software, all or some of the steps can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed by a computer, all or some of the steps generate the processes or functions described in the embodiments of the present application. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer readable storage medium can be any available medium accessible by a computer or a data storage device such as a server, data center, etc. containing one or more available media. The available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, solid state disk (SSD)) and the like.
[0185] It should be noted that, in this document, the terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "and / or" means and or. For example, "A and / or B" means A, B, and A and B. The terms "include", "contain" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitation, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0186] Each of the embodiments in the specification is described in a related manner, and the same or similar parts between each of the embodiments can be referred to each other. Each of the embodiments focuses on the difference from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts can be referred to the part of the method embodiment.
[0187] The above merely provides the preferred embodiments of the application, and not intended to limit the protection scope of the application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the application shall fall within the protection scope of the application.
Claims
1. A method for configuring a read timeout, characterized in that, Applied to business service equipment, the method includes: The interception request template component RestTemplate sends the request parameters to the configuration center device generated by the Hypertext Transfer Protocol (HTTP) interface of the downstream server, so that the configuration center device can obtain the call request corresponding to the request parameters and read the request parameters of the call request. The request parameters include at least the interface name of the HTTP interface and multiple related parameters of the call request. Read the timeout from the target in the configuration; Receive the target read timeout sent by the configuration center device; A target request configuration RequestConfig object is generated based on the target read timeout, and the value of the read timeout parameter in the target RequestConfig object is the target read timeout. Replace the RequestConfig object in the ClientHttpRequest object of the call request with the target RequestConfig object; The call request obtained after the replacement is executed. The process of the configuration center device obtaining the target read timeout corresponding to the request parameters includes: obtaining the reference algorithm corresponding to the interface name in the request parameters, and calculating the target read timeout based on the reference algorithm according to the multiple related parameters.
2. The method according to claim 1, characterized in that, Before intercepting the HTTP call requests generated by RestTemplate for the downstream server's interface, the method further includes: Define an interceptor, which is used to create a class that implements the ClientHttpRequestInterceptor interface. The ClientHttpRequestInterceptor interface is used to call a first method. The first method is used by the business service device to send the request parameters to the configuration center device before executing the call request generated by the RestTemplate, and to replace the RequestConfig object in the ClientHttpRequest object of the call request with the target RequestConfig object. Register the interceptor with the RestTemplate; The interception of call requests generated by RestTemplate for the HTTP interface of the downstream server includes: invoking the interceptor to intercept call requests generated by RestTemplate for the HTTP interface of the downstream server.
3. The method according to claim 1, characterized in that, Replacing the RequestConfig object in the ClientHttpRequest object of the aforementioned call request with the target RequestConfig object includes: Obtain the ClientHttpRequest object of the aforementioned call request; Call the second method to retrieve the Hypertext Transfer Protocol Identifier (HTTP Identifier) from the ClientHttpRequest object and request the HttpUriRequest object; A third method is invoked to configure the target RequestConfig object into the HttpUriRequest object, replacing the RequestConfig object in the HttpUriRequest object.
4. The method according to claim 1, characterized in that, Generate a RequestConfig object based on the target read timeout, including: The fourth method is invoked to generate the RequestConfig object for the aforementioned request; The fifth method is invoked to set the read timeout parameter in the RequestConfig object to the target read timeout.
5. A method for configuring a read timeout, characterized in that, Applied to a configuration center device, the method includes: The system receives request parameters from a business service device, wherein the request is a request generated by the request template component RestTemplate for the Hypertext Transfer Protocol (HTTP) interface of the downstream server, and the request parameters include at least the interface name of the HTTP interface and multiple related parameters of the request. Obtain the target read timeout corresponding to the requested parameters; Send the target read timeout to the service device. The step of obtaining the target read timeout corresponding to the request parameters includes: obtaining the reference algorithm corresponding to the interface name in the request parameters, and calculating the target read timeout by using the reference algorithm based on the multiple related parameters.
6. The method according to claim 5, characterized in that, The relevant parameters include at least one of the following: number of requests, request time, request path, and request header data.
7. A configuration device for reading timeout time, characterized in that, The device, installed in a business service equipment, includes: The interception module is used to intercept the call request generated by the request template component RestTemplate for the Hypertext Transfer Protocol (HTTP) interface of the downstream server, and read the request parameters of the call request. The request parameters include at least the interface name of the HTTP interface and multiple related parameters of the call request. The sending module is used to send the request parameters to the configuration center device so that the configuration center device can obtain the target read timeout time corresponding to the request parameters; The receiving module is used to receive the target read timeout time sent by the configuration center device; The generation module is used to generate a target request configuration RequestConfig object based on the target read timeout time, wherein the read timeout time parameter in the target RequestConfig object is the target read timeout time. The replacement module is used to replace the RequestConfig object in the ClientHttpRequest object of the invocation request with the target RequestConfig object; An execution module is used to execute the replacement call request, wherein the configuration center device obtains the target read timeout time corresponding to the request parameters, including: obtaining the reference algorithm corresponding to the interface name in the request parameters, and calculating the target read timeout time by using the reference algorithm according to the multiple related parameters.
8. A configuration device for reading timeout time, characterized in that, The device, located in the configuration center equipment, includes: The receiving module is used to receive the request parameters of the call request sent by the business service device. The call request is a call request generated by the request template component RestTemplate for the Hypertext Transfer Protocol (HTTP) interface of the downstream server. The request parameters include at least the interface name of the HTTP interface and multiple related parameters of the call request. The acquisition module is used to acquire the target read timeout corresponding to the request parameters; The sending module is used to send the target read timeout to the service device, wherein obtaining the target read timeout corresponding to the request parameters includes: obtaining the reference algorithm corresponding to the interface name in the request parameters, and calculating the target read timeout based on the reference algorithm according to the multiple related parameters.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method according to any one of claims 1 to 4, or implements the steps of the method according to any one of claims 5 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4, or the steps of the method according to any one of claims 5 to 6.
Citation Information
Patent Citations
Interface fusing method and device, server and computer readable storage medium
CN115686912A
Method and device for dynamically adjusting timeout time of RestTemplate request
CN116820629A