2017-04-25 103 views
1

如何追加駱駝交換機構在聚合策略。在駱駝追加交換機構與聚合策略

public class MyAggregationStrategy implements AggregationStrategy { 
    public Exchange aggregate(Exchange newExchange, Exchange originalExchange) { 
     //I want to append body of newExchange to originalExchange. 
     // Currently I'm copying properties with following and returning exchange 
     ExchangeHelper.copyResults(originalExchange, newExchange); 
    }} 
+0

簡短的回答,是的。 –

+0

我該如何實現 – rathna

+0

http://camel.apache.org/aggregator2.html有幾個部分顯示如何追加這些實體。 –

回答

2

既然你寫了「append」,我假設這些主體的類型是java.lang.String。一個簡單的方法是使用一個POJO聚合(看看http://camel.apache.org/aggregator2.html):

public class AppendingAggregator { 
    public String append(String existing, String next) { 
     return existing + next; 
    } 
} 

在你的路線建設者使用

AggregationStrategies.bean(AppendingAggregator.class, "append") 

,你通常會指定的聚合。