2

我正在使用由 jdbc 支持的camel:aggregate,它似乎没有保存 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>

使用聚合器时如何保存属性?

4

1 回答 1

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

基本上,问题出在这一行,其中false表示:不保存属性。

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

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

于 2013-02-05T09:49:12.473 回答