如果远程服务阻塞,我可以发送多少个并发请求?
意思是:当使用WebClient
时,spring在内部使用的maxConnection池限制是多少?
@Autowired
private WebClient webClient;
webClient.post().uri(url).syncBody(req).retrieve().bodyToMono(type);
而且:如何修改它?
最佳答案
在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
关于java - WebClient maxConnection池限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57673715/