【问题标题】:Apache Camel onExceptionOccurred component not redelivering as per the redelivery delayApache Camel onExceptionOccurred 组件未根据重新交付延迟重新交付
【发布时间】:2020-01-27 09:21:29
【问题描述】:

我有 Apache Camel 路由,它调用 restlet 组件并使用来自异常处理程序的重新传递机制,该机制对更新我的数据库记录的每次失败执行一些处理,但如果我提供 2000 的重新传递延迟,则重试需要 24 秒之前的每一次尝试。下面是一段代码。让我知道为什么延迟比预期的要长。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:cxf="http://camel.apache.org/schema/cxf"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="  http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd   http://camel.apache.org/schema/spring       http://camel.apache.org/schema/spring/camel-spring.xsd  http://camel.apache.org/schema/cxf    http://camel.apache.org/schema/cxf/camel-cxf.xsd">
    <!-- CXF Rest Endpoint Declaration -->
    <cxf:rsServer address="http://localhost:9092/rest/corp"
        id="FetchCDFRestRequest" serviceClass="com.tcl.Service.Service" />

    <bean class="com.tcl.ExceptionOccurredRefProcessor" id="exProc" />

    <bean class="org.apache.camel.builder.DeadLetterChannelBuilder"
        id="DLCErrorHandler">
        <property name="deadLetterUri"
            value="activemq:queue:DMS.FAILURES.DLQ" />
        <property name="redeliveryPolicy" ref="redeliveryPolicy" />
    </bean>
    <bean class="org.apache.camel.processor.RedeliveryPolicy"
        id="redeliveryPolicy">
        <property name="maximumRedeliveries"
            value="3" />
        <property name="maximumRedeliveryDelay" value="2000" />
        <property name="retryAttemptedLogLevel" value="WARN" />
    </bean>
    <camelContext id="Corp"
        xmlns="http://camel.apache.org/schema/spring">

        <errorHandler id="eh" onExceptionOccurredRef="exProc">
            <redeliveryPolicy id="redeliveryPolicy" />
        </errorHandler>

        <route errorHandlerRef="DLCErrorHandler"
            id="MainRouteOppIDFolder" streamCache="true">
            <from id="_CreateOppIDFolder"
                uri="restlet:http://localhost:9092/rest/corp/createOppIDFolder?restletMethod=POST" />
            ----------
            <to uri="restlet:http://localhost:9902/CreateOppIDFolder?restletMethod=POST" />
            ------------    
            <onException id="_onException1"
                onExceptionOccurredRef="exProc"
                redeliveryPolicyRef="redeliveryPolicy" useOriginalMessage="true">
                <exception>java.lang.Exception</exception>
                <handled>
                    <simple>true</simple>
                </handled>
                <log id="_log3" loggingLevel="INFO"
                    message="Handled ex >>>>> ${exception.message} " />
            </onException>
        </route>
    </camelContext>
</beans>

以下是一些日志

14:47:52.701 [Restlet-1879974483] 警告 o.a.c.processor.DeadLetterChannel - ExchangeId 上的 (MessageId: ID-DESKTOP-P2DBOO5-1580115331236-0-19 上的传递失败: ID-DESKTOP-P2DBOO5-1580115331236-0-20 )。交付尝试:0 捕获:org.apache.camel.component.restlet.RestletOperationException:Restlet 操作调用http://localhost:9902/CreateOppIDFolder 失败,状态码:500 /n responseBody:org.apache.cxf.interceptor.Fault:无法发送消息。

14:48:15.044 [Camel (MyCamel) 线程 #15 - ErrorHandlerRedeliveryTask] 警告 o.a.c.processor.DeadLetterChannel - ExchangeId: ID-DESKTOP-P2DBOO5 上的 (MessageId: ID-DESKTOP-P2DBOO5-1580115331236-0-19 传递失败: ID-DESKTOP-P2DBOO5 -1580115331236-0-20)。交付尝试:1 捕获:org.apache.camel.component.restlet.RestletOperationException:Restlet 操作调用http://localhost:9902/CreateOppIDFolder 失败,状态代码:500 /n responseBody:org.apache.cxf.interceptor.Fault:无法发送消息。

14:48:37.252 [Camel (MyCamel) 线程 #17 - ErrorHandlerRedeliveryTask] 警告 o.a.c.processor.DeadLetterChannel - ExchangeId: ID-DESKTOP-P2DBOO5 上的 (MessageId: ID-DESKTOP-P2DBOO5-1580115331236-0-19 传递失败: ID-DESKTOP-P2DBOO5 -1580115331236-0-20)。交付尝试:2 捕获:org.apache.camel.component.restlet.RestletOperationException:Restlet 操作调用 http://localhost:9902/CreateOppIDFolder 失败,状态代码:500 /n responseBody:org.apache.cxf.interceptor.Fault:无法发送消息。

有什么建议吗?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    您确定(开始)重试需要 24 秒吗?

    难道不是需要大约 24 秒 重试失败(重试结束)吗?

    所有三个日志语句都从目标端点报告错误 500。是否有可能在 2 秒后开始重试,进行 HTTP 调用,但又需要 20 秒,直到端点回答错误 500?

    00:00 error occurs
    00:02 Camel triggers retry after 2 seconds
    00:02 HTTP call to http://localhost:9902...
    00:xx Waiting for reponse from http://localhost:9902
    00:2x Log output after 20-something seconds that retry is failed
    

    【讨论】:

    • 是的,如果我提供 2 秒作为重新发送延迟,则开始下一次重试大约需要 24 秒。如果重试失败,不确定如何花费 24 秒。我不确定,认为骆驼默认需要 22 秒,如果我们将重新传递延迟设置为 0 秒,如果我们将延迟设置为 2 秒,它会添加到默认延迟并重试下一次重新传递。
    • 我更新了我的答案,因为我认为你没有明白我的意思。我想说的是,Camel在2秒后正确触发重试,但是您的日志输出是重试的最终结果,而不是起点。
    • 嗯,好的,知道了。我怎样才能获得下一个重新交付时间戳,骆驼有什么属性吗?
    • 我不知道,但您可以将 HTTP 端点更改为不存在的东西。这应该会给出非常快速的响应。如果重试日志显示得更快(大约 2 秒后),我的猜测是正确的。
    猜你喜欢
    • 2020-05-09
    • 2020-09-18
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 2014-12-15
    • 1970-01-01
    相关资源
    最近更新 更多