Spring web flux WebClient : 连接由同行休息,已在以下站点观察到以 error.Error 终止的#block
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 客户端调用休息api。我收到以下错误。
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]
是我的 Web 客户端调用还是我正在调用的 api 有问题?
我很困惑,因为它显示了许多错误,例如 Connection rest by peers,#block terminated with an error.Error has been observed at the following site.
如何解决这个问题?
请找到下面的代码
@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();
请帮我找出问题所在。提前致谢
添加客户端Connector后问题解决
private ClientHttpConnector connector() {
return new
ReactorClientHttpConnector(HttpClient.create(ConnectionProvider.newConnection()));
}
WebClient.builder()
.clientConnector(connector())
.exchangeStrategies(exchangeStrategies)
.baseUrl(baseurl)
.build();
我正在使用spring web flux,web 客户端调用休息api。我收到以下错误。
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]
是我的 Web 客户端调用还是我正在调用的 api 有问题? 我很困惑,因为它显示了许多错误,例如 Connection rest by peers,#block terminated with an error.Error has been observed at the following site. 如何解决这个问题? 请找到下面的代码
@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();
请帮我找出问题所在。提前致谢
添加客户端Connector后问题解决
private ClientHttpConnector connector() {
return new
ReactorClientHttpConnector(HttpClient.create(ConnectionProvider.newConnection()));
}
WebClient.builder()
.clientConnector(connector())
.exchangeStrategies(exchangeStrategies)
.baseUrl(baseurl)
.build();