【发布时间】:2021-09-02 14:00:35
【问题描述】:
收到对 HTTP 请求的响应后,我收到了 DataBufferLimitException。我正在使用spring-boot-starter-parent:2.5.0、spring-cloud.version:2020.0.2。
我几乎尝试了这里(DataBufferLimitException: Exceeded limit on max bytes to buffer webflux error)和这里(configure spring.codec.max-in-memory-size When using ReactiveElasticsearchClient)描述的所有选项,但没有成功。还有什么我可以尝试的吗?这是我创建网络客户端的代码:
private WebClient buildWebClient(long custId) {
return WebClient.builder()
.clientConnector(createWebClientWithTimeout())
// Add base url to all requests (callers only need to add the path and query params)
.baseUrl(baseUrl)
// Filter to add bearer token to auth header before sending request
.filter((request, next) -> getToken(custId).map(setAuthHeader(request)).flatMap(next::exchange))
// Filter to send the request, and try again if it has an auth error
.filter((request, next) -> next.exchange(request).flatMap(clientResponse -> {
if (clientResponse.statusCode() == HttpStatus.UNAUTHORIZED) {
logger.error("Received 401 Unauthorized from linkedin for request: {} {} with X-LI-UUID header: {}", request.method(), request.url(),
clientResponse.headers().header(LINKEDIN_HEADER));
// Retry once if auth failed
return clientResponse.bodyToMono(String.class)
.doOnNext(err -> logger.warn("Received 401 from linkedin; retrying once. Error body: {}", err))
.then(refreshToken(custId).map(setAuthHeader(request)).flatMap(next::exchange));
} else if (clientResponse.statusCode().isError()) {
logger.error("Received error status code: {} from linkedin for request: {} {} with X-LI-UUID header: {}", clientResponse.statusCode(), request.method(),
request.url(), clientResponse.headers().header(LINKEDIN_HEADER));
} else {
logger.debug("Received status code: {} from linkedin for request: {} {}", clientResponse.statusCode(), request.method(), request.url());
}
// If not a 401, just return the response
return Mono.just(clientResponse);
})).build();
}
向属性添加 spring.codec.max-in-memory-size=16MB 不起作用,使用 ExchangeStrategies 显式设置值不起作用,实现 WebFluxConfigurer 不起作用。 这段代码在 spring-boot-starter-parent:2.1.6.RELEASE 上运行良好。 关于下一步我可以尝试什么的任何建议?
【问题讨论】:
标签: spring-boot spring-webflux