2013-02-04 34 views
2

我正在使用驼峰:聚合支持jdbc,它似乎不保存Exchange属性。例如,如果我配置了以下路由,并且一旦聚集完成并且在执行camel之前就停止执行:to(log)强制聚集在重新启动时从数据库检索数据,则camel:to(log)将不会打印性能myProperty的骆驼:聚合器不会持久交换属性

<camel:route id="myRoute"> 
    <camel:from uri="direct:in"/> 

    <camel:setProperty propertyName="myProperty"> 
     <camel:constant>myPropertyValue</camel:constant> 
    </camel:setProperty> 

    <camel:aggregate strategyRef="myStrategy" aggregationRepositoryRef="myAggregationRepo" discardOnCompletionTimeout="true" completionTimeout="86400000" > 
     <camel:correlationExpression> 
      <camel:simple>${property.partlastcorrelationkey}</camel:simple> 
     </camel:correlationExpression> 
     <camel:completionPredicate> 
      <camel:simple>${property.partlastcorrelationwaitmore} == false</camel:simple> 
     </camel:completionPredicate> 

     <camel:to uri="log:com.test?showAll=true"/> 

    </camel:aggregate> 
</camel:route> 

我的聚集库配置是这样的:

<bean id="myAggregationRepo" class="org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository" init-method="start" destroy-method="stop"> 
    <property name="transactionManager" ref="transactionManager"/> 
    <property name="repositoryName" value="PROC_AGG"/> 
    <property name="dataSource" ref="oracle-ds"/> 
    <property name="lobHandler"> 
     <bean class="org.springframework.jdbc.support.lob.OracleLobHandler"> 
      <property name="nativeJdbcExtractor"> 
       <bean class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/> 
      </property> 
     </bean> 
    </property> 
</bean> 

我如何使用聚合时节省特性?

回答

2

我会回复我自己。作为对代码所示JdbcCamelCodec不允许与数据库备份的聚合时保存属性:

public final class JdbcCamelCodec { 
    public byte[] marshallExchange(CamelContext camelContext, Exchange exchange) throws IOException { 
     // use DefaultExchangeHolder to marshal to a serialized object 
     DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false); 
     // add the aggregated size property as the only property we want to retain 
     DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); 
     // add the aggregated completed by property to retain 
     DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); 
     // add the aggregated correlation key property to retain 
     DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); 
     // persist the from endpoint as well 
     if (exchange.getFromEndpoint() != null) { 
      DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); 
     } 
    return encode(pe); 
} 

基本上,问题就出在这条线,其中是指:不保存特性。

DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false); 

标题和正文是存储在数据库中的唯一标题和正文。