I am making a project using Spring WebFlux.
In the past I had used StreamingResponseBody
for streaming responses back to the client, but I can't find the equivalent in WebFlux.
Example:
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
@GetMapping("/video")
public StreamingResponseBody stream() {
InputStream videoStream = ...
StreamingResponseBody res = (os) -> { IOUtils.copy(videoStream, os); }
return res;
}
Is there an equivalent of StreamingResponseBody
for WebFlux? or, should I import the traditional Spring MVC and mix them?
Edit: So far I am solving it by accessing the ServerHttpResponse
(example below). But I am still wondering about better solutions.
@GetMapping("/video")
fun stream2(response: ServerHttpResponse): Mono<Void> {
val factory = response.bufferFactory()
val publisher = videoStream
.observeVideoParts()
.map { factory.wrap(it.bytes) }
return response.writeWith(publisher)
}