2

スプリッターを使用して zip ファイル内のファイルを反復処理し、それに沿ってカスタム アグリゲーターも使用して、本体のリスト (メインの zip ファイル内の両方のファイル) を提供します。さて、その分割の後、アグリゲーターの結果で発生するアグリゲーション ブロック処理中にヘッダー セットを抽出したいと思います。しかし、アグリゲーターの出力が失われたようで、分割ブロックの後に何も返されません。

私はこれの基本を得ていないと確信しています。誰かがここで助けてくれれば幸いです。

<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;
    }
}
4

1 に答える 1

1

集計ロジックを分割スコープ内に保持する必要があります。以下のように、分割の集計を行う単一の集計インスタンスが必要です。

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

上記のコードのように、分割タグで集計戦略を属性として指定する必要があります。そのため、すべての反復による交換リターンは、集計戦略 Bean to Aggregate で使用できます。

それが役に立てば幸い :)

于 2015-08-28T06:46:26.703 に答える