【问题标题】:Apache Camel onExceptionOccurred component not redelivering as mentioned timesApache Camel onExceptionOccurred 组件未按上述时间重新交付
【发布时间】:2020-05-09 13:44:10
【问题描述】:

我有一个调用 restlet 组件的 Apache Camel 路由。为了更好地了解运行时发生的情况,我还将执行状态保存在数据库中(重试次数、上次执行状态)。我想使用异常处理程序中的重新传递机制,但它会在每次更新我的数据库记录失败时执行一些处理。

<bean class="com.tcl.ExceptionOccurredRefProcessor" id="exProc" />
<camelContext errorHandlerRef="eh">
<errorHandler id="eh" onExceptionOccurredRef="exProc"> <redeliveryPolicy 
            maximumRedeliveries="3" maximumRedeliveryDelay="2000" 
            retryAttemptedLogLevel="WARN" />
</errorHandler>
<to uri="-------"/> //Invoke rest service
<onException id="_onException1" onExceptionOccurredRef="exProc" useOriginalMessage="true">
                <exception>java.lang.Exception</exception>
                <handled>
                    <simple>true</simple>
                </handled>
                ...........
   </onException>
</camelContext>

为此,我尝试将 onExceptionOccurred 组件与 redelivery 组件一起使用,并在 camelContext 上引用,如上面的代码,但消息仅传递一次并停止执行。

有什么建议吗?

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    首先:您粘贴的代码有点混乱,因为没有 Camel 路线,只是一个普通的 to 元素,在 Camel 上下文中不能单独存在。

    但是,我想您的问题是“隐藏的”骆驼处理。如 Camel Docs of the Exception Clause 中所述,onException 子句默认将 maximumRedeliveries 覆盖为 0,除非您明确设置该选项。

    <onException>
        <exception>java.lang.Exception</exception> // max. redelivery = 0
    </onException>
    
    <onException>
        <exception>java.lang.Exception</exception> 
        <redeliveryPolicy maximumRedeliveries="3"/> // max. redelivery = 3
    </onException>
    

    我不确定maximumRedeliveryDelay 等其他重新投递选项,但如果没有明确设置,至少maximumRedeliveries 会被覆盖。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多