Reputation: 37
I have a multithreading project where I read a message from a queue and pass it to spring integration to process it. Each messages goes though diff channel end up storing in DB and sending to downstream Qs.
<int:channel id="mainChannel">
<int:interceptors>
<int:wire-tap channel="channel1" selector-expression="!headers['somevalue']"/>
<int:wire-tap channel="channel2" selector-expression="!headers['somevalue']"/>
<int:wire-tap channel="channel3" selector-expression="!headers['somevalue']"/>
</int:interceptors>
</int:channel>
<int:channel id="channel1">
<int:dispatcher task-executor="exec1" />
</int:channel>
<int:channel id="channel2">
<int:dispatcher task-executor="exec2" />
</int:channel>
<int:channel id="channel3">
<int:dispatcher task-executor="exec3" />
</int:channel>
Now I want to block the sender thread until all the async tasks are finished processing e.g say in thread one only message goes to all channel(1,2,3) and for another thread it will go to only 2 channel (1,2) and so on.
I have seen aggregator/Thread barrier approach but not sure how it will work since for each thread flow will be diff.
How I can achieve this?
Upvotes: 0
Views: 483
Reputation: 174664
The threading doesn't matter; the main thread calls the barrier and whichever thread adds the 3rd message to the aggregator will release the group which can then be used to trigger the barrier.
https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#barrier
Upvotes: 0