Given an infinite flux of objects, where each object has an ID, how can I use flux to create a buffered list of updates grouped by ID property (keeping the last emitted value)? Thanks Example Something like the following would be perfect but it seems to wait the end of the flux in my tests instead of buffering. It works
Tag: reactor
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
Reactive – Improve Mono syntax
I have this block of code that works fine: To summarize it: calls the isBlacklistedToken function (returns a Mono<Boolean> with the result of the refresh token) If the refresh token is blacklisted, throws an UnauthorizedException If the refresh token is not blacklisted, does the same process for the access token If both tokens are not blacklisted, finally blacklists them. This
what’s the meaning of server.onDispose().block()?
There are few web pages about reactor-netty on the internet. And I don’t understand the meaning of some code below. These code below is just ABC of reactor-netty. But I really can not find more information on the internet. So I have to ask for help. Please help me with the five places in the code above. Thank you. Answer
How to convert a Flux<List> to a merged Flux?
While working with Project Reactor, there came a use case where I’d want to convert a Flux <List<String>> to a <Flux<String>> where all those lists are flattened to form a Flux. Is there any out of the box method for the same? Answer Use .flatMap(Flux::fromIterable)
How do I compare the values in ‘Mono’?
Comparing the values in Mono<Integer> a and Mono<Integer> b, if the value in Mono<Integer> a is larger, I want to throw an error. Answer
Smart way to handle nested flux operations
I have 2 query methods (findByName/findAnotherName) . Both of them return Mono<List> . I do some logic by compare results of these two methods, and then return one of them in a nested Flux operation. It may have a smart way to achieve same result though. Following is code snippet: Thanks in advance. Answer https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html#zipWhen-java.util.function.Function-java.util.function.BiFunction- If your //do some logic
What are worker threads, and what is their role in the reactor pattern?
I’m trying to understand the Reactor pattern (concurrent), but in many examples they are talking about ‘worker threads’. What are worker threads? In what way do they differ from ‘normal’ threads? And what is their role in the reactor pattern? Answer The Reactor pattern is used with worker threads to overcome a common scenario in applications: You need to do