Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

webclient timeout

@Configuration
@EnableWebFlux
public class WebFluxConfig implements WebFluxConfigurer
{  
  Logger logger = LoggerFactory.getLogger(WebFluxConfig.class);
   
  @Bean
  public WebClient getWebClient()
  {
    HttpClient httpClient = HttpClient.create()
            .tcpConfiguration(client ->
            		// Here there are global timeout
                    client.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                    .doOnConnected(conn -> conn
                            .addHandlerLast(new ReadTimeoutHandler(10))
                            .addHandlerLast(new WriteTimeoutHandler(10))));
     
    ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient.wiretap(true));     
 
    return WebClient.builder()
            .baseUrl("http://localhost:3000")
            .clientConnector(connector)
            .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
            .build();
  }
}
Source by howtodoinjava.com #
 
PREVIOUS NEXT
Tagged: #webclient #timeout
ADD COMMENT
Topic
Name
4+1 =