Spring Cloud Gateway是否支持来自上游的大文件响应?



我有一个服务可以提供大于100mb的大文件。

我已经尝试设置Spring云网关与路由和谓词:https://spring.io/projects/spring-cloud-gateway

也尝试了ProxyExchange: https://cloud.spring.io/spring-cloud-gateway/multi/multi__building_a_simple_gateway_using_spring_mvc_or_webflux.html

两种方式都不能处理大文件:

org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 2097152
at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:98) ~[spring-core-5.3.10.jar:5.3.10]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):

即使我将限制增加到10mb,这也是不够的。

Spring Cloud Gateway是否支持来自上游的大文件响应?是否有可能将这样的响应流式传输,而不试图将其全部加载到内存中?

最后,事实证明只有ProxyExchange不能处理大型响应,而常规网关配置可以处理它们:

@RestController
class DownloadController {
@RequestMapping(value = "/proxy", produces = "application/gzip")
public Mono<? extends ResponseEntity<?>> proxy(ProxyExchange<byte[]> proxy) {
// Does not support large files
return proxy.uri("https://distro.ibiblio.org/tinycorelinux/5.x/x86/release/distribution_files/core.gz")
.sensitive()
.forward();
}
}
@Configuration
class GatewayConfiguration {
@Bean
public RouteLocator configure(RouteLocatorBuilder builder) {
// Supports Large files
return builder.routes()
.route(predicateSpec -> predicateSpec.path("/gateway")
.filters(gatewayFilterSpec -> gatewayFilterSpec.setPath("/tinycorelinux/5.x/x86/release/distribution_files/core.gz"))
.uri("https://distro.ibiblio.org"))
.build();
}
}

相关内容

  • 没有找到相关文章

最新更新