如何在路线级别进行corrleationId复制?并且仅当未填充CorrelationID时

时间:2012-11-20 17:38:21

标签: apache-camel

我的用例(骆驼):

  • 如果传入的消息有correlationId(比如clientCorrId)=>因为这样做,什么都不做,因为clientCorrId被客户用来映射响应。

  • 如果传入的消息没有correlationId =>获取messageId并将其放在correlationId中(在路由级别,而不是在使用“jms”组件的每个路由中)

复制correlationId只能在路由级别

进行

如何在路由级别进行corrleationId复制? (不像在useMessageIDAsCorrelationID中那样全局,如下所示)

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory" ref="jmsConnectionFactory" />
    <!--property name="useMessageIDAsCorrelationID" value="true" / WARNING! Do not use this as we need to copy only in the beginning not everywhere -->
    <property name="transactionManager" ref="jpaTransactionManager" />
    <property name="transacted" value="true" />
</bean>

我想避免像这样单独的bean代码来复制correlationId ONLYIF它是空的

    if (EMPTY_MSG_ID.equals(currentCorrId)) {
        log.info("No corrId set, setting msgId to corrid :" + msgId);
        outHeader.put(correlationIdKey, msgId);
    } else {
        outHeader.put(correlationIdKey, currentCorrId);
        log.info("CorrId already set: " + currentCorrId);
    }

1 个答案:

答案 0 :(得分:0)

您可以使用拦截器从jms端点进行拦截,并在需要时添加缺少的ID。见http://camel.apache.org/intercept