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 picture and quote I understand that flatMap allows the creation of more (or fewer) elements than it was
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 occurs. Here is the reusable
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 want to terminate
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 Mono from your repository methods, you can do this I would recommend you to start
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. For each webclient, you can
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 result of my AggregateService
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 a response. Recently, we’ve been discussing whether we are unnecessarily spending resources using a reactive module in our
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 sufficient for a webflux-webservice in spring-boot. Answer RestController annotation is part of org.springframework:spring-web: dependency org.springframework:spring-web dependency is part of org.springframework.boot:spring-boot-starter-webflux jar so it should get resolved. You can check
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 the super class of ClassA and therefore the return type of ClassA.getMonoA() which is Mono<ClassA> does
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 so-called side-effect operators and should not