I do have a requirement where I am having call to 3 APIs in which one of the API is dependent on the output of other. If we say we are having 3 APIs A, B and C A and B can run in parallel but C is dependent on the output of B.
Below is the pseudo code for the same.
public IntegrationFlow mainFlow()
{
return flow -> flow
.scatterGather(scatterRequests(), aggregateResponse())
.enrichHeaders(s -> s.headerExpressions(h -> h.put(AGGREGATED_RESPONSE, "payload")))
.scatterGather(scatterOtherRequests(), aggregateResponse());
}
private Consumer<RecipientListRouterSpec> scatterRequests()
{
return scatterer -> scatterer
.applySequence(true)
.recipientFlow(flowA())
.recipientFlow(flowB());
}
private Consumer<RecipientListRouterSpec> scatterOtherRequests()
{
return scatterer -> scatterer
.applySequence(true)
.recipientFlow(flowC())
.recipientFlow(aggregatedResponseSubFlow());
}
where aggregatedResponseSubFlow is as below
private IntegrationFlow raggregatedResponseSubFlow()
{
return subflow -> subflow
.handle((payload, headers) -> {
return headers.get(AGGREGATED_RESPONSE);
});
}
Even though there are 2 Scattergathers one after the other, both of them run in parallel due to which I get inconsistent results. So how can I run it sequentially. i.e after the execution of 1st one the 2nd one should get started. If it cannot be done how else can the scenario be handled?
Note: I do need to aggregate responses from all 3 services