首页 > 解决方案 > Apache Camel onExceptionOccurred 组件未根据重新交付延迟重新交付

问题描述

我有 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] WARN oacprocessor.DeadLetterChannel - (MessageId: ID-DESKTOP-P2DBOO5-1580115331236-0-19 on ExchangeId: 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] 警告 oacprocessor.DeadLetterChannel - ExchangeId 上的 (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] 警告 oacprocessor.DeadLetterChannel - ExchangeId 上的 (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

解决方案


您确定(开始)重试需要 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

推荐阅读