Converting Uni.combine().all().unis() approach to transformToUniAndConcatenate

127 views Asked by At

I have read the answer below from Clement on fetching a list of results from an external service using Uni vs Multi: Uni.combine().all().unis() v.s. Multi..onItem().transformToMultiAndConcatenate().collect()

Currently my code looks like this, where uniResponses only has two events:

uniResponses = requests.stream().map(event -> client.create(event)).toList();
return uni.onItem()
.call(() -> Uni.combine().all().unis(uniResponses).discardItems());

I have had problems with getting all responses from the external service after the fact. How can I ensure that both event responses are populated, but done in a non-blocking fashion?

The event responses are handled by a EventResponseListener, which has a process method, and pushes the response object to CosmosDB repo

protected Uni<Void> process(final ResponseEvent event){

final ResponseData data = event.getData);
return repo.getResponseObjectByIdAsync(data.getId())
.onFailure(ConcurrentModificationException.class)
.retry().withBackOff(Duration.ofSeconds(2)).withJitter(0.3).atMost(2)
.onItem()
.transformToUni(item -> {
return repo.patch(item.getId(), item.getDerivedId(), item.getResponses())
.onFailure(ConcurrentModificationException.class)
.retry().withBackOff(Duration.ofSeconds(2)).withJitter(0.3).atMost(2)
.onItem()
.transformToUni(responseService::sendUpdate).replaceWithVoid();
});

where the responses array would have two response objects

ResponseObject(Outcome SUCCESS), ResponseObject(Outcome SUCCESS)

but instead have only one response object due to concurrency issues

ResponseObject(Outcome IN_PROGRESS)
0

There are 0 answers