jdbc - Camel : Aggregator doesn't persist Exchange properties

标签 jdbc properties exchange-server aggregator

我正在使用 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>

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

最佳答案

我自己回复吧。如代码所示,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);

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

关于jdbc - Camel : Aggregator doesn't persist Exchange properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14685918/

相关文章:

java.sql.SQLException : ORA-01403: no data found at struct. getDescriptor().getMetaData() 异常

graph - Neo4j遍历时节点属性比较

javascript - 对象的方法可以将要恢复的对象本身的名称存储为 JavaScript 中的字符串吗?

c# - 连接到 Exchange - 入门教程?

java - 在核心java中,从用户获取输入并将其插入mysql数据库时,显示错误sql错误

java - Teradata JDBC 创建 volatile 表错误 3585

java - 用于模拟的可编程 JDBC 驱动程序

objective-c - 当设置为只读时,property_getAttributes() 不会区分保留、强、弱和分配属性

php - 通过 PHP IMAP 连接到 Exchange 服务器,Exchange 服务器对 UNSEEN 电子邮件使用什么标志?

powershell - 激活交换PowerShell命令