I'm using scatter gather pattern which uses three parallel flows. I can see the aggregated groupMessage consists of the responses coming in order of which comes first. Can I change the index of the messages that are grouped together in aggregate() method by using correlationId and sequenceNumber?
public IntegrationFlow flow() {
return flow ->
.split()
.channel(c -> c.executor(Executors.newCachedThreadPool()))
.scatterGather(
scatterer ->
scatterer
.applySequence(true)
.recipientFlow(flow1())
.recipientFlow(flow2())
.recipientFlow(flow3()),
gatherer -> gatherer.releaseLockBeforeSend(true))
.log("Gatherer")
.aggregate(aggregatingAndFormingRequestForFlow4())
.to(flow4())
public MessageGroupProcessor aggregatingAndFormingRequestForFlow4() {
return group -> {
System.out.println("Get Messages: " + group.getMessages())
// here I need to send three responses as arguments to do further processing but as group is a list in the runtime I don't know the index
prepareRequest()
/// }
Here if I see the log :
INFO [pool-12-thread-1]Gatherer:GenericMessage [payload=[response from flow1, response from flow2, response from flow3 ], headers={sequenceNumber=1, sequenceDetails=[[f4da9a6f-f27d-91ac-cbef-5106eb614d62, 1, 1]], errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1b6efbf0, sequenceSize=1, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1b6efbf0,correlationId=f4da9a6f-f27d-91ac-cbef-5106eb614d62, id=378f5406-ce9e-19fb-c909-5d5c7c4093c0, timestamp=1662660858032}]
Get Messages: [payload=[response from flow1, response from flow2, response from flow3 ], headers={sequenceNumber=1, sequenceDetails=[[f4da9a6f-f27d-91ac-cbef-5106eb614d62, 1, 1]], errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1b6efbf0, sequenceSize=1, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1b6efbf0,correlationId=f4da9a6f-f27d-91ac-cbef-5106eb614d62, id=378f5406-ce9e-19fb-c909-5d5c7c4093c0, timestamp=1662660858032}]
u can see the log it's an array of three responses combined.