httpcomponents作为webclient的底层客户端,获取连接超时,webclient没有立即返回

使用httpcomponents作为webclient的底层客户端连接,配置最大连接数为1,从池中获取连接的超时时间为0.2秒。

创建一个接口sleep(30000),并用webclient连续调用两次,发现第二次调用并不会因获取不到连接而立即返回,而是等第一次结束后(30s后)才返回 Caused by: org.apache.hc.core5.util.DeadlineTimeoutException。

如果直接用httpClient会因0.2秒内未从池中获取到空闲连接而抛出 ConnectionRequestTimeoutException。请问webclient为什么和httpClient表现不一样,是我漏掉了什么配置,还是因为用httpClient作为底层连接的兼容性问题吗?

webclient调用方式如下:

@Slf4j
@RestController
@Tag(name = "测试WebClient", description = "测试WebClient")
@RequestMapping(path = "/testWebClient", consumes = {MediaType.ALL_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE})
public class TestWebClientController {
    @Resource
    private WebClient webClient;

    @GetMapping("/testGet")
    @Operation(summary = "WebClient的get请求", description = "WebClient的get请求")
    public R<Object> get() {
        CountDownLatch countDownLatch = new CountDownLatch(2);

        Mono<R> resp = webClient.get()
                .uri(uriBuilder -> uriBuilder
                        .scheme("http")
                        .host("localhost")
                        .port(60001)
                        .path("/baseservice/user/get")
                        .queryParam("id", 1)
                        .build())
                .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToMono(R.class);
        return R.success(resp.block());
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值