标签: spring5

Spring WebClient reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException

我正在使用 Spring WebClient 调用休息服务。如下所述的 post 调用代码。

Mono<ClientResponse> response = client.post()
                        .uri(uriBuilder -> uriBuilder.build())
                        .headers(httpHeaders -> httpHeaders.setAll(getHeaders()))
                        .body(BodyInserters.fromPublisher(Mono.just(message), String.class))
                        .exchange();
                response.subscribe(clientResponse -> {
                   System.out.println(clientResponse.statusCode());
                });
Run Code Online (Sandbox Code Playgroud)

在连续发布一段时间后(在 5 分钟内发布 2-3 百万个请求后),我收到以下异常。

 [     parallel-3] r.c.s.Schedulers                         : Scheduler worker in group main failed with an uncaught exception

reactor.core.Exceptions$ErrorCallbackNotImplemented: reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms
Caused by: reactor.netty.internal.shaded.reactor.pool.PoolAcquireTimeoutException: Pool#acquire(Duration) has been pending for more than the configured timeout of 45000ms
    at reactor.netty.internal.shaded.reactor.pool.AbstractPool$Borrower.run(AbstractPool.java:317) ~[reactor-netty-0.9.0.RELEASE.jar!/:0.9.0.RELEASE]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been …
Run Code Online (Sandbox Code Playgroud)

webclient reactive spring5

8
推荐指数
1
解决办法
4389
查看次数

如何确定 Spring WebClient 是否使用 HTTP/2?

我想知道 Spring WebClient 是否使用 HTTP/2。我怎么能确定呢?

http2 spring-webflux spring-webclient spring5

7
推荐指数
2
解决办法
2535
查看次数

使用 Spring WebClient 返回完整的响应

我有以下代码

public ClientResponse doGet(HttpServletRequest request, URI uri) {
    return webClient.get()
            .uri(uri.toASCIIString())
            .headers(headers -> headers.putAll(processRequest(request))
            .exchange()
            .block();
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试通过 RestController 返回此 ClientResponse 时,如下所示,

@GetMapping
@ResponseBody
public ClientResponse doGet(HttpServletRequest request) {
    ClientResponse node = service.doGet(request);
    return node;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

org.springframework.http.converter.HttpMessageNotWritableException:找不到类型返回值的转换器:类org.springframework.web.reactive.function.client.DefaultClientResponse

基本上,我想要的最终目标是将实际响应返回给调用者 - 包括标头、正文、cookie等。

我正在考虑像下面这样使用 ResponseEntity 。

public ResponseEntity<JsonNode> doGet2(HttpServletRequest request, URI uri) {

    Mono<ClientResponse> clientResponse = webClient.get()
            .uri(uri.toASCIIString())
            .headers(headers -> headers.putAll(processRequest(request))
            .exchange();

    HttpHeaders headers = clientResponse.map(resp -> resp.headers().asHttpHeaders()).block();
    JsonNode body = clientResponse.flatMap(resp -> resp.bodyToMono(JsonNode.class)).block();

    ResponseEntity<JsonNode> jsonNode = ResponseEntity.ok().headers(headers).body(body);
    return jsonNode; …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-webclient spring5

4
推荐指数
1
解决办法
2万
查看次数

如何在 Spring Webflux 中获取引用网址?

如何在 Spring Webflux 中获取引用网址?我尝试查看ServerWebExchange exchange对象中的标头属性,但找不到相同的属性。有人可以帮我吗?

java spring-webflux spring-boot-2 spring-reactive spring5

3
推荐指数
1
解决办法
4322
查看次数