Given the following method: switchIfEmpty and map operators mutate the profileUpdate object. Is it safe to mutate in switchIfEmpty operator? Regarding map, if I have understood correctly, this is not safe and object profileUpdate must be immutable, right? eg: Later in the chain, another method mutates the object: The above methods are called as follows: Answer Nebulous answer, but… it
Tag: reactive-programming
How to call long running blocking void returning method with Mutiny reactive programming?
I have a chain of Async and Sync method invocation on Mutiny’s Uni, some methods are a long-running process with return type void. What is the proper way of invoking/calling them without blocking downstream? Below is the simple analogy code. Answer In general, use runSubscriptionOn and pass a specific executor: Note that it will constraint the concurrency to the number
Java reactor how to properly start async cancellable sideeffect
I’m trying to write something using reactor which I know how to write using completable futures. I’m getting “Calling subscribe in non-blocking scope” warning in it. My goal is to call turnOn() with a timeout which should call turnOff() after the timeout. If turnOn() is called again it should cancel the old timeout and wait for a new timeout. How
Asynchronous Programming and Reactive Programming
This question is in my mind about a year. Actually are there any differences in Asysnchronus and Non-blocking. When we call the blocking part in our code then it becomes blocking which is synchronous and at the same time it will not be non-blocking. If we are creating another thread apart from main thread to make asynchronous programming and we
Merge two api responses into one using Webclient – Webflux
I’m using WebFlux and WebClient and I need to consume two APIs and merge its responses. The first API receive type and document number and returns a list with one element that contains customer data (that’s how it’s defined). The second API receive a client id and returns a customer payments list. I need to consume these two APIs and
How to handle file access in a reactive environment
I’m refactoring some blocking code to reactive (using Reactor). I think most of the methods in the java.nio.file.Files class are blocking. Is it right if I replace a method like: with: I think it’s necessary, especially when cheap HDDs are used. Or does a library exists in Reactor for this kind of file manipulation? Answer Generally yes, but your code
Use case of Flux and Mono
I am new to world of Flux and Monos, and recently, while using the findAll() method, I realized that this method is capable of returning partial responses , i.e via the Flux , and I need to do append a block() if i need all the records from the CosmosDB. I was wondering what could possibly be the real world
RSocket retrieveFlux() with Kotlin
I am trying to write a client for my server (both in Kotlin and using Spring Reactive Web). I encountered this problem while trying to use the RSocket. How can I get a Flux using RSocket? Answer You need to get reference of Class. You can use either Int::class.java or Int::class depending whether you need java Class or KClass reference
WebFlux – how to check if Mono<ResponseEntity<Flux>> is empty to return 404
My code: When I pass not existing email, my code returns response 200 with empty array: [] In this case I’d like to return 404 error – why the last line is not executed? A method getUserTreeGroups: And method findUserTreeGroup: I want to return to the frontend a list of TreeItem. And to be honest – I still don’t understand
Obtaining a nested objects using Spring Data R2DBC
I’m new to Project Reactor and R2DBC. How to receive and merge Flux<Child> with Mono<Parent> properly using Spring Data R2DBC reactive repositories? Parent: ParentRepository: Child: ChildRepository: ParentPersistenceAdapter: My solution is: Answer Assuming the existence of a withChildren(Flux<Child> children) type method, you can just do: However, this is a bit odd – you wouldn’t usually have a Flux on a DAO