I’ve read that wonderful answer about the difference between map and flatMap. And there is a picture that demonstrates flatmap: And quote: The map is for synchronous, non-blocking, one-to-one transformations while the flatMap is for asynchronous (non-blocking) One-to-Many transformations. Based on that …
Tag: spring-webflux
How to throw custom exception when using Spring webclient exchange method?
I have created a reusable method that returns the headers, status, and body of an HTTP call using the Spring webclient’s exchange method. I want to capture the 4xx and 5xx errors in the method itself and log the response body. However, i am not able to return/throw custom exception when 4xx or 5xx error…
Webflux execute a sequence of actions in sequential order and get their result
I have this issue with Webflux which I don’t seem to have a valid solution for: I have an item, T, which I need to process using n Webflux actions. Each action is a function that takes T and returns Mono<T>. I could execute the actions on the item using flatMapSequential, but the issue is that I w…
Spring boot WebFlux : How to write Mono.map() return value?
Exception is : Required type: Mono Provided:Mono no instance(s) of type variable(s) T exist so that Mono conforms to UserDto inference variable R has incompatible bounds: equality constraints: UserDto lower bounds: Mono How to write function getUserInfoByUserId ? Answer Assuming that you are always returning …
Java Specific webclient connect timeout per request
I have to call different urls with different connection timeout with webclient. But i found that we can set connect timeout globally only and not per resquest .. what to do please to set this timeout on a request without creating a new weblient each time. Answer You need to instantiate one webclient per url. …
How make sequential API calls and merge the result in a mono
I try to make sequential API calls and merge the result in a mono . The first API contains a List of Id for the second API. My functional WebClient The ouvrageClient was invoked but I don’t see log Log The ouvrageClient was invoked but I don’t see log for the ouvrageClient …. and the global …
Does the use of Spring Webflux’s WebClient in a blocking application design cause a larger use of resources than RestTemplate
I am working on several spring-boot applications which have the traditional pattern of thread-per-request. We are using Spring-boot-webflux to acquire WebClient to perform our RESTful integration between the applications. Hence our application design requires that we block the publisher right after receiving …
How to add @RestController to spring-webflux apps?
The annotation @RestController cannot be resolved when only adding spring-boot-starter-webflux as maven dependency: pom.xml: What is missing here? According to many resources out there (eg https://medium.com/javarevisited/basic-introduction-to-spring-webflux-eb155f501b17), the webflux dependency should be suf…
Problem of type inference and type variance for Reactor/WebFlux
Let’s say there is an interface and its implement class as: And then, for the method Mono<InterfaceA> getMonoA(), the following implementation causes a compile error: It makes sense that the invariance type Mono<InterfaceA> is not the super class of Mono<ClassA> even if InterfaceA is t…
How to chain reactive calls correctly and sequentially
I am trying to make calls with the following order: save an object publish an object creation event, only if the first step is done Return a Flux list What I have currently is following: Would this work and publish event as requested, or should I use zipWhen() instead of doOnSuccess()? Answer doOn… are …