Spring MVC controller is to be used as a proxy for another service to serving possibly large files.
To avoid storing the whole WebClient response from another service in memory at any given time I wanted to use reactive properties of Spring 5 + Reactor project and stream its response as it's consumed by the browser.
The current code looks like
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()
}
}
And it causes
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]
- How to configure the controller to handle
Mono<ClientResponse>
? - If the response is of type
Mono
will the request be backpressured? Is there a need to convert it to bytes chunks and make itFlow
? - Spring documentation says a lot of benefits of backpressure but doesn't answer the question above, nor gives any warning about
Mono
response. Is it still reactive?