Can you perform a zero-copy upload and download with Spring 5 WebFlux using org.springframework.web.reactive.function.client.WebClient
?
You're right, zero-copy is supported for now when posting data from a File-based Resource
.
So the following looks right:
client.post()
.body(BodyInserters.fromResource(new FileSystemResource(new File("file.txt"))));
Now for the reading part, zero-copy is not supported on the reading side right now in Spring Framework; you could create an enhancement issue on jira.spring.io for that.
Your code sample should look like:
Flux<DataBuffer> incoming = client.post()
.retrieve().bodyToFlux(DataBuffer.class);
Mono<Void> writeOperation = DataBufferUtils.write(incoming, channel)
.map(DataBufferUtils::release)
.then();
// subscribe to the returned value, which will complete when writing is done
Unfortunately, reading data to DataBuffer
won't do zero-copy as data will be copied in memory. I don't think zero-copy is supported right know on the reading side, so this could be an enhancement request on https://jira.spring.io.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With