How to set a timeout in Spring 5 WebFlux WebClient

前端 未结 7 1962
暗喜
暗喜 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条回答
  • 2020-12-01 07:28

    To set the read and connect timeout I use the method below, because the SO_TIMEOUT option is not available for channels using NIO (and giving the warning Unknown channel option 'SO_TIMEOUT' for channel '[id: 0xa716fcb2]')

    ReactorClientHttpConnector connector = new ReactorClientHttpConnector(
              options -> options.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000)
                                .compression(true)
                                .afterNettyContextInit(ctx -> {
                                    ctx.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS));
                                }));
    return WebClient.builder()
                    .clientConnector(connector)
                    .build();
    
    0 讨论(0)
提交回复
热议问题