Apache camel ApacheCamel聚合
我正在使用聚合器将交换聚合到一个列表中,然后将该列表传递给数据库进行批量插入。将其插入第一个表后,列表中的所有对象都将被修改,然后发送到另一个数据库。在执行此操作时,我面临的问题是,有时聚合器作为列表中的一个元素发送以供插入的对象也会在下一个列表中以修改后的值再次发送。 我使用的聚合器策略是:Apache camel ApacheCamel聚合,apache-camel,Apache Camel,我正在使用聚合器将交换聚合到一个列表中,然后将该列表传递给数据库进行批量插入。将其插入第一个表后,列表中的所有对象都将被修改,然后发送到另一个数据库。在执行此操作时,我面临的问题是,有时聚合器作为列表中的一个元素发送以供插入的对象也会在下一个列表中以修改后的值再次发送。 我使用的聚合器策略是: public class ArrayListAggregationStrategy implements AggregationStrategy { public Exchange aggregate(E
public class ArrayListAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Object newBody = newExchange.getIn().getBody();
ArrayList<Object> list = null;
if (oldExchange == null) {
list = new ArrayList<Object>();
list.add(newBody);
newExchange.getIn().setBody(list);
return newExchange;
} else {
list = oldExchange.getIn().getBody(ArrayList.class);
list.add(newBody);
return oldExchange;
}
}
}
公共类ArrayListAggregationStrategy实现聚合策略{
公共交换聚合(交换旧交换、交换新交换){
Object newBody=newExchange.getIn().getBody();
ArrayList list=null;
if(oldExchange==null){
列表=新的ArrayList();
列表。添加(新手);
newExchange.getIn().setBody(列表);
返回newExchange;
}否则{
list=oldExchange.getIn().getBody(ArrayList.class);
列表。添加(新手);
退换货;
}
}
}
同样的路线是:
<routeContext id="coreCdrRoute" xmlns="http://camel.apache.org/schema/spring">
<route errorHandlerRef="CoreErrorHandler" id="coreEngineRoute">
<from
uri="activemq:queue:{{coreEngine.queue}}?concurrentConsumers={{core.consumer}}" />
<log loggingLevel="DEBUG"
message="Message received from core Engine queue is ${body}"></log>
<multicast>
<pipeline>
<setHeader headerName="CamelRedis.Command">
<constant>RPUSH</constant>
</setHeader>
<setHeader headerName="CamelRedis.Key">
<constant>CoreCdrBatch</constant>
</setHeader>
<setHeader headerName="CamelRedis.Value">
<simple>${body}</simple>
</setHeader>
<log loggingLevel="DEBUG" message="Adding to redis value : ${body}"></log>
<to uri="spring-redis://localhost:6379?serializer=#stringSerializer" />
</pipeline>
<pipeline>
<unmarshal ref="gsonCoreEngine"></unmarshal>
<bean beanType="com.bng.upload.processors.GetCdr"
method="process(com.bng.upload.beans.CoreEngineEvent,${exchange})" />
<transform>
<method ref="insertionBean" method="finalCoreCdr"></method>
</transform>
<aggregate strategyRef="aggregatorRef" completionInterval="300000">
<correlationExpression>
<constant>true</constant>
</correlationExpression>
<completionSize>
<simple>${properties:core.batch.size}</simple>
</completionSize>
<to uri="mybatis:batchInsertCore?statementType=InsertList"></to>
<log message="Inserted in masterCallLogs : ${in.header.CamelMyBatisResult}"></log>
<multicast>
<pipeline>
<choice>
<when>
<simple>${properties:coreEngine.write.file} == true</simple>
<setHeader headerName="path">
<simple>${properties:coreEngine.cdr.folder}</simple>
</setHeader>
<bean beanType="com.bng.upload.processors.SaveToFile"
method="processCore(${exchange})" />
<log
message="Going to write ivr cdrs to file : ${in.header.CamelFileName}" />
<to uri="file://?fileExist=Append&bufferSize=32768"></to>
</when>
</choice>
</pipeline>
<pipeline>
<transform>
<method ref="logCounter" method="callConferenceLogs(${exchange})"></method>
</transform>
<choice>
<when>
<simple>${body.size()} != 0</simple>
<to uri="mybatis:callConfCounter?statementType=InsertList"></to>
</when>
</choice>
</pipeline>
</multicast>
</aggregate>
</pipeline>
<bean beanType="com.bng.upload.processors.RedisImpl" method="removeOnInsertion(CoreCdrBatch)" />
<log message="Reached end of transaction for CoreEngine successfully" />
</multicast>
</route>
</routeContext>
突袭
CoreCrDrbatch
${body}
真的
${properties:core.batch.size}
${properties:coreEngine.write.file}==true
${properties:coreEngine.cdr.folder}
${body.size()}!=0
我无法调试我在这里做错了什么。不要走大路。将路线拆分为较小的路线,并使用直接端点将其链接在一起。按照克劳斯的建议,我把这条路线分成几小步,然后再测试一次。但还是有同样的问题。在删除聚合器并使用列表之后,我不再面临上述问题。