How to call a blocking service from my Reactive REST with Quarkus/Mutiny
Solution 1:
You will need to use the chain
operator, as you want to chain the call to service A with the call to service B. So, you will need something like:
public Uni<List<Shop>> checkout(Person person) {
// Represent the call to the Service A
Uni<List<Shop>> shopsUni = shopService.find("person_id", person.getId()).list();
return shopsUni.chain(shops -> {
// Here is a small subtility.
// You want to call the Service B multiple times (once per shop),
// so we will use "join" which will call the Service B multiple times
// and then we _join_ the results.
List<Uni<Void>> callsToServiceB = new ArrayList<>();
for (Shop shop: shops) {
// I'm assuming productService.checkout returns a Uni<Void>
callsToServiceB.add(productService.checkout(shop));
}
// Now join the result. The service B will be called concurrently
return Uni.join(callsToServiceB).andFailFast()
// fail fast stops after the first failure.
// replace the result with the list of shops as in the question
.replaceWith(shops);
});
}