Hello Quarkus community,
I'm struggling with my first attempts to create a reactive service (preferably with Mutiny).
The use case is the following:
I get a list of items from an async api (Promise SearchResult),
then I complete (transform) each item with other information (new type),
before I send the item to storage.
This pretty much sound like a nice stream. So, my first idea was wrapping things:
public Multi<Item> getResult(){
ItemResult result = async.call().get() // get of the Promise
return Multi.createFrom().iterable(result.getItems());
}
And
public Uni<CustomType> buildCutomType(Item item){
//Do stuff to build new obj
return Uni.createFrom().item(obj);
}
The problem I have is to find the correct sequence of functions like:
adapter.getResult() //return Multi<Item>
.onItem()
.transform(item -> buildCutomType(item)) //as this returns Uni<CustomType> do I need to "transformToUni"?
.onItem()
.call(obj -> repo.store(obj)); //necessary to wait at the end for completion?
Maybe, the approach to wrap things like above is already wrong, and it's better to return a Uni<ItemResult> at the beginning, but then again I need to stream the single items out of it?? Hmmm :-/
I checked the "reactive" topics in the guides and the Mutiny docs, but there is a lack of complex examples.
A little guidance on that topic would be very much appreciated
Regards,
Daniel