How to set a timeout in Spring 5 WebFlux WebClient

前端 未结 7 1964
暗喜
暗喜 2020-12-01 06:30

I\'m trying to set timeout on my WebClient, here is the current code :

SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManag         


        
7条回答
  •  -上瘾入骨i
    2020-12-01 07:19

    Here's how I did it (thanks to @Artem)

    SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    
            ClientHttpConnector httpConnector = new ReactorClientHttpConnector(options -> {
                options.sslContext(sslContext);
                options.option(ChannelOption.SO_TIMEOUT, this.applicationConfig.getHttpClientRequestTimeout());
                options.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, this.applicationConfig.getHttpClientConnectTimeout());
                options.poolResources(PoolResources.fixed("myPool", this.applicationConfig.getHttpClientMaxPoolSize()));
            });
    
            return WebClient.builder().clientConnector(httpConnector).defaultHeader("Authorization", "xxxx")
                    .baseUrl(this.config.getBaseURL()).build();
    

提交回复
热议问题