简体   繁体   English

骆驼/ ActiveMQ交易,重新交付和DLQ

[英]Camel/ActiveMQ Transactions, Redelivery and DLQs

Using Fabric8 379 build. 使用Fabric8 379构建。

Currently struggling with ActiveMQ & Camel getting the desired behaviours of TransactionErrorHandler to work as expected. 当前正在与ActiveMQ和Camel挣扎,以使TransactionErrorHandler的期望行为能够按预期工作。

Firstly as per the Camel error handler documentation ( http://camel.apache.org/error-handler.html ) if I invoke the TransactionErrorHandler as suggested ie 首先,如果我按照建议的方式调用TransactionErrorHandler,则按照Camel错误处理程序文档( http://camel.apache.org/error-handler.html

<errorHandler id="txEH" type="TransactionErrorHandler">
<redeliveryPolicy logStackTrace="false" logExhausted="false" maximumRedeliveries="3"/>
</errorHandler>

I get an error: 我收到一个错误:

Caused by: org.xml.sax.SAXParseException: cvc-enumeration-valid: Value 'TransactionErrorHandler' is not facet-valid with respect to enumeration '[DeadLetterChannel, DefaultErrorHandler, NoErrorHandler, LoggingErrorHandler]'. It must be a value from the enumeration.

Which is fair enough, I guess TransactionErrorHandler has been removed from the schema and has to be invoked differently? 哪一个公平,我猜想TransactionErrorHandler已从架构中删除,必须以不同的方式调用? So if I go the alternative route and specify a TransactionErrorHandler bean like so: 因此,如果我走替代路线并像下面这样指定一个TransactionErrorHandler bean:

<bean id="transactionErrorHandler"
    class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
    <property name="deadLetterUri" value="activemq:queue:ActiveMQ.DLQ" />
    <property name="redeliveryPolicy" ref="redeliveryPolicy" /> 
</bean>

<bean id="redeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
    <property name="backOffMultiplier" value="2" />
    <property name="maximumRedeliveries" value="2" />
    <property name="redeliveryDelay" value="1000" />
    <property name="useExponentialBackOff" value="true" />
</bean> 

I can successfully use this within my route by specifying errorHandlerRef="transactionErrorHandler". 通过指定errorHandlerRef =“ transactionErrorHandler”,我可以在路由中成功使用它。 However when testing this scenario, the redeliveryPolicy is completely ignored, with redelivery attempts being 6 (default) rather than the 2 specified above. 但是,在测试此方案时,将完全忽略redeliveryPolicy,重新交付尝试次数为6(默认),而不是上面指定的2。 I am hoping someone can point me in the right direction around how to properly specify a TransactionErrorHandler within a route. 我希望有人可以指出正确的方向,围绕如何正确指定路由内的TransactionErrorHandler。 Below is my current test blueprint.xml, which is deployed onto a fabric: 下面是我当前的测试blueprint.xml,它已部署到结构上:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
    xmlns:camel="http://camel.apache.org/schema/blueprint"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
                              http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
                              http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd 
                              http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd">

    <!-- blueprint property placeholders -->
    <cm:property-placeholder id="test-adapter" persistent-id="uk.test.transactions">
        <cm:default-properties>
            <cm:property name="amqBrokerURL" value="discovery:(fabric:platform)" />
            <cm:property name="amqBrokerUserName" value="admin" />
            <cm:property name="amqBrokerPassword" value="admin" />
        </cm:default-properties>
    </cm:property-placeholder>

    <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="TestRouteContext" useMDCLogging="true">

        <!-- <errorHandler id="txEH" type="TransactionErrorHandler">
            <redeliveryPolicy logStackTrace="false"
                logExhausted="false" />
        </errorHandler> -->

        <route id="platform-test-route" errorHandlerRef="txEH">
            <from uri="activemq:queue:test-queue-in" />
            <transacted ref="transactionPolicy" />
                    <!-- Basic Bean that logs a message -->
            <bean ref="stubSuccess" />
                    <!-- Basic Bean that throws a java.lang.Exception-->
            <bean ref="stubFailure" />
            <to uri="activemq:queue:test-queue-out" />
        </route>

    </camelContext>

    <bean id="stubSuccess" class="uk.test.transactions.stubs.StubSuccess" />

    <bean id="stubFailure" class="uk.test.transactions.stubs.StubFailure" />

    <bean id="transactionErrorHandler"
        class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
        <property name="deadLetterUri" value="activemq:queue:ActiveMQ.DLQ" />
        <property name="redeliveryPolicy" ref="redeliveryPolicy" /> 
    </bean>

    <bean id="transactionPolicy" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager" ref="jmsTransactionManager" />
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" />
    </bean>

    <bean id="jmsTransactionManager"
        class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="jmsPooledConnectionFactory" />
    </bean>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="connectionFactory" ref="jmsPooledConnectionFactory" />
        <property name="transacted" value="true" />
        <property name="transactionManager" ref="jmsTransactionManager" />
        <property name="cacheLevelName" value="CACHE_CONSUMER" />
    </bean>

    <bean id="jmsPooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
        init-method="start" destroy-method="stop">
        <property name="maxConnections" value="1" />
        <property name="connectionFactory" ref="jmsConnectionFactory" />
    </bean>

<!--    <bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
        <property name="backOffMultiplier" value="2" />
        <property name="initialRedeliveryDelay" value="2000" />
        <property name="maximumRedeliveries" value="2" />
        <property name="redeliveryDelay" value="1000" />
        <property name="useExponentialBackOff" value="true" />
    </bean> -->

    <bean id="redeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
        <property name="backOffMultiplier" value="2" />
        <property name="maximumRedeliveries" value="2" />
        <property name="redeliveryDelay" value="1000" />
        <property name="useExponentialBackOff" value="true" />
    </bean> 

    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="${amqBrokerURL}" />
        <property name="userName" value="${amqBrokerUserName}" />
        <property name="password" value="${amqBrokerPassword}" />
        <property name="watchTopicAdvisories" value="false" />
        <!-- <property name="redeliveryPolicy" ref="redeliveryPolicy" /> -->
    </bean>

</blueprint>  

If anyone could see where I am going wrong it would be much appreciated. 如果有人看到我要去哪里错了,将不胜感激。

您应该在AMQ代理上配置重新交付选项,就像使用TX时一样,它负责进行重新交付的代理(不是骆驼)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM