Spring gateway route timeout principle analysis and gateway call process

1. HttpClientProperties set gateway routing timeout

/** The connect timeout in millis, the default is 45s. */
private Integer connectTimeout;

/** The response timeout. */
private Duration responseTimeout; 

2. GatewayAutoConfiguration configuration class When the user does not configure httpclient, the gatewayHttpClient method will use HttpClientProperties to configure the httpclient object and configure the default tcp connectTimeout of httpclient.

It will also configure the largest response header, Proxy, ssl, ConnectionProvider according to HttpClientProperties

@Bean
@ConditionalOnMissingBean
public HttpClient gatewayHttpClient(HttpClientProperties properties,
      List<HttpClientCustomizer> customizers) {
 
  
  

3. NettyRoutingFilter is responsible for routing service calls. In this class, some parameters of remote calls are set according to routing configuration.

The getHttpClient method will try to obtain the connect-timeout from the routing information, and if it exists, set the connectTimeout parameter of tcp.

The getResponseTimeout method will try to get the response-timeout parameter from the routing information, if it exists, set a timeout callback for the http call

 
 
protected HttpClient getHttpClient(Route route, ServerWebExchange exchange) {
   Object connectTime

Guess you like

Origin blog.csdn.net/weixin_39355187/article/details/126224944