Spring web flux WebClient : Connection rest by peers,#block terminated with an error.Error has been observed at the following site

huangapple go评论75阅读模式
英文:

Spring web flux WebClient : Connection rest by peers,#block terminated with an error.Error has been observed at the following site

问题

以下是您提供的内容的翻译:

我正在使用Spring Web Flux和Web Client调用一个REST API,但是我遇到了以下错误。

Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	被抑制的异常:java.lang.Exception: #块以错误结束 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 		位于 reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) ~[reactor-core-3.3.2.RELEASE.jar!/:3.3.2.RELEASE] 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 		... 97个公共帧被省略 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	由 io.netty.channel.unix.Errors$NativeIoException 引起:readAddress(..) 失败:连接被对等方重置 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	被抑制的异常:reactor.core.publisher.FluxOnAssembly$OnAssemblyException:  
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	在以下位置观察到错误: 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	|_ checkpoint ? 请求以获取 https://cc-qa.app/api/matches/list/?status=current&page=0&size=100 [DefaultWebClient] 

问题是出在我的Web Client调用还是我正在调用的API上?
我感到困惑,因为它显示了许多错误,如连接被对等方重置,#块以错误结束。在以下位置观察到错误。
如何解决这个问题?
请在下面找到代码:

  @Bean
  public WebClient restClient() {

    String baseurl = env.getProperty("base-url");
    int memoryLimit = Integer.parseInt(env.getProperty("webclient-buffer-size"));

    ExchangeStrategies exchangeStrategies =
        ExchangeStrategies.builder()
            .codecs(
                configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * memoryLimit))
            .build();
    return WebClient.builder()
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();
  }

这是API调用的部分:

webClient
              .get()
              .uri("/api/matches/list/?status=current&page=0&size=100")
              .header("authorization", accessToken)
              .retrieve()
              .bodyToMono(InfoPayload.class)
              .block();

请帮我找出问题所在。提前感谢您的帮助。

英文:

i am using spring web flux, web client to call a rest api. i am getting the following error.

Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	Suppressed: java.lang.Exception: #block terminated with an error 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99) ~[reactor-core-3.3.2.RELEASE.jar!/:3.3.2.RELEASE] 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 		... 97 common frames omitted 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 Caused by: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:  
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 Error has been observed at the following site(s): 
Oct 21 09:46:27 ql-hybrid-stg web.7d755d6967-5d7v8 	|_ checkpoint ? Request to GET https://cc-qa.app/api/matches/list/?status=current&page=0&size=100 [DefaultWebClient] 

is the problem with my web client call or the api i am calling ?
i am confused as it showing many error like Connection rest by peers,#block terminated with an error.Error has been observed at the following site.
how to solve this ?
please find the code below

  @Bean
  public WebClient restClient() {

    String baseurl = env.getProperty("base-url");
    int memoryLimit = Integer.parseInt(env.getProperty("webclient-buffer-size"));

    ExchangeStrategies exchangeStrategies =
        ExchangeStrategies.builder()
            .codecs(
                configurer -> configurer.defaultCodecs().maxInMemorySize(1024 * 1024 * memoryLimit))
            .build();
    return WebClient.builder()
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();
  }

this the api call:

webClient
              .get()
              .uri("/api/matches/list/?status=current&page=0&size=100")
              .header("authorization", accessToken)
              .retrieve()
              .bodyToMono(InfoPayload.class)
              .block();

please help me to find the issue . thanks in advance

答案1

得分: 3

问题在添加客户端连接器之后得以解决。

 private ClientHttpConnector connector() {
    return new 
 ReactorClientHttpConnector(HttpClient.create(ConnectionProvider.newConnection()));
  }

WebClient.builder()
        .clientConnector(connector())
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();
英文:

the problem solved after adding the client Connector.

 private ClientHttpConnector connector() {
    return new 
 ReactorClientHttpConnector(HttpClient.create(ConnectionProvider.newConnection()));
  }

WebClient.builder()
        .clientConnector(connector())
        .exchangeStrategies(exchangeStrategies)
        .baseUrl(baseurl)
        .build();

</details>



# 答案2
**得分**: 2

对于我来说,添加baseUrl解决了这个问题。只需对现有的`WebClient/WebTestClient`实例调用`.mutate()`,然后设置`.baseUrl(<>)`。

<details>
<summary>英文:</summary>

For me adding the baseUrl solved the issue. Just `.mutate()` the existing instance of `WebClient/WebTestClient` and set the `.baseUrl(&lt;&gt;)`

</details>



huangapple
  • 本文由 发表于 2020年10月21日 13:14:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/64457096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定