In my Quarkus service, I need to fetch a list of results from external service, and I figured out there are two methods to achieve the same goal:
1st approach based on Uni.combine().all():
List<Uni<Result>> results = new ArrayList();
for (Parameter p : parameters) {
// callService returns Uni<Result>
results.add(callService(p));
}
// collect all the results
Uni<List<Result>> combined = Uni.combine().all().unis(results)...
2nd approach based on Multi..onItem().transformToMultiAndConcatenate().collect()
Multi.createFrom().iterable(parameters)
.onItem()
.transformToMultiAndConcatenate(p -> callService(p))
.collect().asList()
In the beginning I don't think there exists any true difference between the two approaches, as Uni are evaluated lazily and either Uni.combine or Multi.collect are like syntax sugar to me. But I still would like to ask if there exists any difference? especially performance-wise difference.
With the 1st approach, I am debugging an error that when the size of parameters exceeds 25 it starts to give error but under 25 it is fine. Therefore I suspect it 1st approach shall incur a very high QPS that floods the external service. However, I doubt the 2nd approach will help with throttling either.