Spring MVC 控制器将用作另一个服务的代理,以服务可能的大文件。
为了避免在任何给定时间将来自另一个服务的整个 WebClient 响应存储在内存中,我想使用 Spring 5 + Reactor 项目的反应性属性并在浏览器使用它时流式传输其响应。
当前代码看起来像
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.reactive.function.client.ClientResponse
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Mono
@Controller
class ReportController {
@GetMapping("/reports")
fun getReport(): Mono<ClientResponse> {
val webCient = WebClient.create()
return webCient
.get()
.uri("http://localhost:3333/file")
.exchange()
}
}
它导致
java.lang.IllegalStateException: Could not resolve view with name 'reports'.
at org.springframework.web.reactive.result.view.ViewResolutionResultHandler.lambda$resolveViews$3(ViewResolutionResultHandler.java:277) ~[spring-webflux-5.0.6.RELEASE.jar:5.0.6.RELEASE]
- 如何配置控制器来处理
Mono<ClientResponse>
? - 如果响应是类型
Mono
的,请求会被背压吗?是否需要将其转换为字节块并制作它Flow
? - Spring 文档说明了背压的很多好处,但没有回答上述问题,也没有给出任何关于
Mono
响应的警告。它仍然是反应性的吗?