2 years ago
#67317
Samshay
How can i consume a Flux<DataBuffer> with WebClient
I have this controller :
@GetMapping(value = "/stream")
public Flux<DataBuffer> stream() {
...
return webClient.get().uri(builder.buildAndExpand(parametres).toUriString())
.header(HttpHeaders.CONTENT_TYPE, TEXT_CSV).retrieve().bodyToFlux(DataBuffer.class);
}
}
When i called this endpoint with PostMan, i have this reponse :
[
{
"nativeBuffer": {
"direct": true,
"readOnly": false,
"contiguous": true,
"readable": true,
"writable": false
},
"allocated": true
},
...
My question is, how can i consume this endoint with webclient to read the content of flux. Or perhaps, the controller is wrong ?
I tried this, but it's don't work :
Flux<DataBuffer> fluxDataBuffer= webClient.get()
.uri("http://localhost:8080/stream")
.retrieve()
.bodyToFlux(DataBuffer.class);
DataBufferUtils.write(fluxDataBuffer, Paths.get("test.txt"),
StandardOpenOption.CREATE)
.share().block();
Thanks for your help
java
spring
stream
webclient
webflux
0 Answers
Your Answer