WebClient 最大连接池限制?

mem*_*und 6 java spring spring-boot spring-webflux spring-webclient

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

@Autowired
private WebClient webClient;

webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);
Run Code Online (Sandbox Code Playgroud)

此外:我该如何修改它?

Ale*_*kin 8

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

要更改连接池限制,您可以定义自己的WebClient.Builderbean 并使用它来创建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));
}
Run Code Online (Sandbox Code Playgroud)

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