Questions tagged [spring-webflux]

Spring Framework 5 includes a new spring-webflux module. The module contains support for reactive HTTP and WebSocket clients as well as for reactive server web applications including REST, HTML browser, and WebSocket style interactions. WebFlux can run on Servlet containers with support for the Servlet 3.1 non-blocking I/O API as well as on other async runtimes such as Netty and Undertow.

Questions tagged spring-webflux should be about applications using the Spring WebFlux framework.

If Spring Boot is involved, please also tag the question with spring-boot. If the question is related to the use of Reactor operators, please tag the question with project-reactor as well.

For Spring WebFlux related documentation, please refer to the:

6050 questions
50
votes
6 answers

How to correctly read Flux and convert it to a single inputStream

I'm using WebClient and custom BodyExtractorclass for my spring-boot application WebClient webLCient = WebClient.create(); webClient.get() .uri(url, params) .accept(MediaType.APPLICATION.XML) .exchange() .flatMap(response -> { …
Bk Santiago
  • 1,523
  • 3
  • 13
  • 24
49
votes
2 answers

Right way to use Spring WebClient in multi-thread environment

I have one question regarding Spring Framework WebClient In my application I need to do many similar API calls, sometimes I need to change headers in the calls (Authentication token). So the question arises, what would be better of the two…
Sergey Luchko
  • 2,996
  • 3
  • 31
  • 51
49
votes
14 answers

Spring Webflux : Webclient : Get body on error

I am using the webclient from spring webflux, like this : WebClient.create() .post() .uri(url) .syncBody(body) .accept(MediaType.APPLICATION_JSON) .headers(headers) .exchange() …
adrien le roy
  • 823
  • 2
  • 7
  • 12
45
votes
6 answers

block()/blockFirst()/blockLast() are blocking error when calling bodyToMono AFTER exchange()

I am trying to use Webflux to stream a generated file to another location, however, if the generation of the file ran into an error, the api returns success, but with a DTO detailing the errors while generating the file instead of the file itself.…
DaithiG
  • 849
  • 1
  • 9
  • 15
44
votes
2 answers

Difference between @Controller and RouterFunction in Spring 5 WebFlux

There are two ways to expose HTTP endpoints in spring 5 now. @Controller or @RestController by making the controller's class, e.g. @RestController @RequestMapping("persons") public class PersonController { @Autowired private PersonRepo…
Deepak Kumar
  • 1,669
  • 3
  • 16
  • 36
43
votes
2 answers

Cant autowire `WebTestClient` - no auto configuration

We are using spring framework 5 and spring boot 2.0.0.M6 and we are also using WebClient for reactive programming. We created test methods for our reactive rest endpoints and so I looked up for some example on how to do it. I found this one or this…
Mulgard
  • 9,877
  • 34
  • 129
  • 232
41
votes
1 answer

What is then, thenEmpty, thenMany and flatMapMany in spring webflux?

I don't understand the use and the difference between then, thenEmpty, thenMany and flatMapMany on Flux or Mono in spring webflux.
Amr Khaled
  • 421
  • 1
  • 4
  • 5
40
votes
5 answers

Timeout on blocking read for 5000 MILLISECONDS in Spring Webflux

I wrote a test for Handler (Spring Webflux) @Test public void checkServicesHandlerTest() { Request request = new Request(); request.setMsisdn("ffdfdfd"); this.testClient.post().uri("/check") .body(Mono.just(request),…
Mikhail
  • 2,690
  • 4
  • 28
  • 43
38
votes
3 answers

Deserialize a json array to objects using Jackson and WebClient

I have a problem during the deserialization of a json array using Spring. I have this json response from a service: [ { "symbol": "XRPETH", "orderId": 12122, "clientOrderId": "xxx", "price": "0.00000000", …
Justin
  • 1,149
  • 2
  • 19
  • 35
37
votes
3 answers

Spring boot Webclient's retrieve vs exchange

I have started using WebClient in my Spring boot project recently. Can somebody throw some light on the differences/usages between exchange and retrieve methods in WebClient. I understand that exchange returns Mono and retrieve…
37
votes
2 answers

Spring WebFlux differences when Netty vs. Tomcat is used under the hood

I am learninig spring webflux and I've read the following series of articles(first, second, third) In the third Article I faced the following text: Remember the same application code runs on Tomcat, Jetty or Netty. Currently, the Tomcat and Jetty…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
37
votes
11 answers

How to extract response header & status code from Spring 5 WebClient ClientResponse

I am new to Spring Reactive framework & trying to convert Springboot 1.5.x code into Springboot 2.0. I need to return response header after some filtering, body & status code from Spring 5 WebClient ClientResponse. I do not want to use block()…
Renus11
  • 371
  • 1
  • 3
  • 5
37
votes
2 answers

How to make reactive webclient follow 3XX-redirects?

I have created a basic REST controller which makes requests using the reactive Webclient in Spring-boot 2 using netty. @RestController @RequestMapping("/test") @Log4j2 public class TestController { private WebClient client; @PostConstruct …
37
votes
3 answers

How to get response body when testing the status code in WebFlux WebClient?

How do you retrieve the response body when trying to throw an exception based on the returned status code? For instance, lets say I want to throw an exception and reject HTTP 201. client.post().exchange().doOnSuccess(response -> { if…
CoryO
  • 533
  • 1
  • 5
  • 11
35
votes
2 answers

Mono.Defer() vs Mono.create() vs Mono.just()?

Could someone help me to understand the difference between: Mono.defer() Mono.create() Mono.just() How to use it properly?
Anton Tb
  • 417
  • 1
  • 5
  • 8