在camel中,如何通过Aggregate Strategy中的aggregate()返回多个交换

时间:2014-09-29 05:06:40

标签: java apache-camel

在camel中,如何通过AggregateStrategy中的aggregate()返回多个funnge。 我写逻辑来聚合两个csv文件,我想根据某些条件生成3个不同的文件,所以我想发送3个交换对象,我想将它发送到不同的路由器。

1 个答案:

答案 0 :(得分:2)

您实际上无法从聚合器返回多个交换。

但是,您可以让聚合器返回Collection个所有CSV记录,split,然后route根据您提到的条件将其返回到三个不同的路径。

如果您愿意,可以在每条路线上

汇总过滤后的CSV记录。

<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 -->
...