Guide to "Reactive" for Spring MVC Developers
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about using WebClient and reactive types inside blocking Spring MVC applications, since it comes from a Spring maintainer.
Recommended by 2 people across 2 different months, 2019 to 2022.
What it is
A SpringOne Platform 2018 conference talk by Spring team member Rossen Stoyanchev on how developers with existing Spring MVC applications can use reactive features without moving to a full WebFlux stack. It covers WebClient, reactive repositories, orchestrating remote calls, response streaming, testing and debugging, plus the limits of Spring MVC compared with WebFlux.
What people said
Recommends Krzysztof Skrzynecki · 2019-08 · Stack Overflow · on “Download Large file from server using REST template Java Spring MVC”
As @bernie [LINK] mentioned you can use WebClient to achieve this: public Flux<DataBuffer> downloadFileUrl( ) throws IOException { WebClient webClient = WebClient.create(); // Request service to get file data return Flux<DataBuffer> fileDataStream = webClient.get() .uri( this.fileUrl ) .accept( MediaType.APPLICATION_OCTET_STREAM ) .retrieve() .bodyToFlux( DataBuffer.class ); } @GetMapping( produces = MediaType.APPLICATION_OCTET_STREAM_VALUE ) public void downloadFile( HttpServletResponse response ) throws IOException { Flux<DataBuffer> dataStream = this.downloadFileUrl( ); // Streams the stream from response instead of loading it all in memory DataBufferUtils.write( dataStream, response.getO
Recommends Tomaz Fernandes · 2022-05 · Stack Overflow · on “Does the use of Spring Webflux's WebClient in a blocking application design cause a larger use of resources than RestTemplate”
In this presentation [this video] Rossen Stoyanchev from the Spring team explains some of these points. WebClient will use a limited number of threads - 2 per core for a total of 12 threads on my local machine - to handle all requests and their responses in the application. So if your application receives 100 requests and makes one request to an external server for each, WebClient will handle all of those using those threads in a non-blocking / asynchronous manner. Of course, as you mention, once you call block your original thread will block, so it would be 100 threads + 12 threads for a total of 112 threads to handle those requests. But keep in mind that these 12 threads do not grow in size as
Cites Gonen I · 2019-07 · Stack Overflow · on “Getting values of Objects from Monos in a list after blocking for all of them”
I am following Rossen Stoyanchev's demo on Spring Reactive [this video] , and calling three delayed API's and then blocking until they are all done. List<Mono<Person>> personMonos = Stream.of(1, 2, 3) .map(i -> client.get().uri("/person/{id}", i).retrieve().bodyToMono(Person.class)) .collect(Collectors.toList()); // Declare that we want to block until all monos in the list are done Mono.when(personMonos).block(); Next, can I get the values of the three returned Person object's after blocking completed for the three calls? If so, how?