Apache camel apachecamel:获取聚合器&x27;谁的反应?

Apache camel apachecamel:获取聚合器&x27;谁的反应?,apache-camel,aggregator,Apache Camel,Aggregator,我们使用一个拆分器来迭代压缩文件中的文件,同时,我们还使用了一个自定义聚合器,它为我们提供了一个主体列表——主压缩文件中的两个文件。现在,在分割之后,我想提取在聚合器结果上发生的聚合块处理期间设置的头。但是,聚合器的输出似乎丢失了,在分割块之后,我什么也没有得到 我肯定我没有掌握这方面的基本知识。如果有人能帮忙,我将不胜感激 <route id="main-route"> <split streaming="true"> <r

我们使用一个拆分器来迭代压缩文件中的文件,同时,我们还使用了一个自定义聚合器,它为我们提供了一个主体列表——主压缩文件中的两个文件。现在,在分割之后,我想提取在聚合器结果上发生的聚合块处理期间设置的头。但是,聚合器的输出似乎丢失了,在分割块之后,我什么也没有得到

我肯定我没有掌握这方面的基本知识。如果有人能帮忙,我将不胜感激

<route id="main-route">
        <split streaming="true">
            <ref>zipSplitter</ref>
            <choice>
                <when>
                    <method bean="fileHandler" method="isY" />
                    <to uri="direct:y" />
                </when>
                <otherwise>
                    <to uri="direct:x" />
                </otherwise>
            </choice>
            <to uri="direct:aggregate" />
       </split>
       <!--Do something by extracting the headers set during the processing underneath in the aggregation block i.e. process-data -->
</route>
<route id="aggregate-data">
        <from uri="direct:aggregate" />
        <camel:aggregate strategyRef="aggregationStrategy" completionSize="2">
            <camel:correlationExpression>
                <constant>true</constant>
            </camel:correlationExpression>
            <to uri="direct:process-data"/>
        </camel:aggregate>
 </route>

拉链
真的
聚合器-

public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    Object newBody = newExchange.getIn().getBody();
    Map<String, Object> newHeaders = newExchange.getIn().getHeaders();

    ArrayList<Object> list = null;
    if (oldExchange == null) {
        list = new ArrayList<Object>();
        list.add(newBody);
        newExchange.getIn().setBody(list);
        return newExchange;
    } else {
        Map<String, Object> olderHeaders = oldExchange.getIn().getHeaders();
        olderHeaders.putAll(newHeaders);
        list = oldExchange.getIn().getBody(ArrayList.class);

        list.add(newBody);
        return oldExchange;
    }
}
公共交换聚合(交换旧交换、交换新交换){
Object newBody=newExchange.getIn().getBody();
Map newHeaders=newExchange.getIn().getHeaders();
ArrayList list=null;
if(oldExchange==null){
列表=新的ArrayList();
列表。添加(新手);
newExchange.getIn().setBody(列表);
返回newExchange;
}否则{
映射olderHeaders=oldExchange.getIn().getHeaders();
旧标题。putAll(新标题);
list=oldExchange.getIn().getBody(ArrayList.class);
列表。添加(新手);
退换货;
}
}

您必须将聚合逻辑保持在拆分范围内。应该有一个聚合实例为您的拆分进行聚合,如下所示

     <route id="main-route">
        <split streaming="true" strategyRef="aggregationStrategy">
            <ref>zipSplitter</ref>
            <choice>
                <when>
                    <method bean="fileHandler" method="isY" />
                    <to uri="direct:y" />
                </when>
                <otherwise>
                    <to uri="direct:x" />
                </otherwise>
            </choice>               
       </split>
  </route>

拉链
您必须在split标记中将聚合策略指定为类似于上述代码的属性。所以,每次迭代的交换返回将在聚合策略bean中可用,以进行聚合

希望有帮助:)