java - WebClient maxConnection池限制?

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

如果远程服务阻塞,我可以发送多少个并发请求?
意思是:当使用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/

相关文章:

javascript - VertX Webserver 静态内容 webroot

java - 堆栈溢出二叉搜索树计算深度

java - 在使用 Job Scheduler API 的作业服务中使用 GoogleApiClient - 缺少回调

java - spring中如何缓存列表?

javascript - 如何更改 <spring :message code> 中的代码值

java - 无法打开 JPA EntityManager 进行事务 - 通信链接失败(Spring-boot/jpa/hibernate/连接池)

java - 如何使用 Java 中的 ta-lib 修复 RSI 计算输出中的零?

java - Spring 批 : Cannot determine embedded database driver class for database type NONE

java - 将列名更改为其他时,TableView提供错误

spring-boot - 使用Spring的@EnableRedisHttpSession时如何在 Controller 中获取session或redis key的过期时间?