WebClient maxConnection池限制?

时间:2019-08-27 11:29:17

标签: java spring spring-boot spring-webflux spring-webclient

如果远程服务被阻止,我可以发送多少个并发请求? 意思是:使用WebClient时spring在内部使用的 maxConnection 池限制是什么?

@Autowired
private WebClient webClient;

webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);

而且:如何修改它?

2 个答案:

答案 0 :(得分:1)

来自网络documentation

  

默认情况下,TCP客户端使用“固定”连接池,其中500为   最大通道数和45s作为获取超时。

答案 1 :(得分:1)

在Reactor-netty 0.9.0.M4版本之前,由于使用了“弹性”连接提供程序,因此默认情况下没有限制。 This fix将其更改为“固定”连接提供程序,限制为500。

要更改连接池限制,您可以定义自己的WebClient.Builder bean并使用它来创建WebClient

@Bean
public WebClient.Builder webClientBuilder() {
    String connectionProviderName = "myConnectionProvider";
    int maxConnections = 100;
    int acquireTimeout = 1000;
    HttpClient httpClient = HttpClient.create(ConnectionProvider
            .fixed(connectionProviderName, maxConnections, acquireTimeout));
    return WebClient.builder()
            .clientConnector(new ReactorClientHttpConnector(httpClient));
}

或者您可以以与预定义的org.springframework.boot.web.reactive.function.client.WebClientCustomizer相同的方式实现自定义WebClient.Builder

相关问题