Reputation: 11
In camel, how to return multiple exhanges by aggregate() in AggregateStrategy. I write logic to aggregate two csv files and i want to generate 3 different files based on some condition, so that i want to send 3 exchange objects and i want to send it to different router.
Upvotes: 0
Views: 529
Reputation: 3349
You can't actually return multiple exchanges from an aggregator.
However, you can make your aggregator return a Collection
of all the CSV records, split them, then route them to three different routes based on the condition you mentioned.
on each route you can aggregate the filtered CSV records if you wish.
<route id="mainRoute">
<from ... />
<!-- this is you aggregator that aggregates the two CSV files' records -->
<aggregate strategyRef="aggregatorStrategy">
...
<!-- split the resulting records (aggregator returned an exchange with a List body)-->
<split>
<simple>${body}</simple>
<choice>
<when>
<!-- your condition here -->
<!-- send to the first category route -->
<to uri="direct:firstCategoryRecords" />
</when>
<when>
<!-- your condition here -->
<!-- send to the second category route -->
<to uri="direct:secondCategoryRecords" />
</when>
<!-- same for third category -->
...
</choice>
</split>
</aggregate>
</route>
<route id="firstCategoryRecordsRoute">
<from uri="direct:firstCategoryRecords" />
<!-- aggregate the filtered CSV records into one file here -->
...
</route>
<!-- rest of the routes -->
...
Upvotes: 2