骆驼延迟优先于任何重新交付政策

时间:2019-11-14 10:51:41

标签: java apache-camel

这是简化的ftp轮询机制。

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

    <redeliveryPolicyProfile id="redeliveryPolicy"
        redeliveryDelay="10000" 
        maximumRedeliveries="-1" />

    <camel:route id="fetchFiles">  
        <camel:from uri="ftp://10.20.30.40/From?username=user&password=RAW({{password}})&delay=3000" />
        <camel:to uri="log:input?showAll=true&level=INFO"/>
        <camel:to uri="file://incomingDirectory" />

        <onException redeliveryPolicyRef="msRedeliveryPolicy">
            <exception>java.lang.Exception</exception>
            <redeliveryPolicy logRetryAttempted="true" retryAttemptedLogLevel="WARN"/>
        </onException>      
    </camel:route>

</camelContext>
  

您认为失败会发生什么? (延迟为3秒,   redeliveryDelay是10秒。)

     

答案:它每3秒钟永久轮询一次。

所以让我们看一下文档。也许我需要

"repeatCount (scheduler)"

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

Default: 0

不是,它甚至不是有效的参数。那为什么在文档中呢?

 Unknown parameters=[{repeatCount=5}]

好,所以我想它每3秒钟轮询一次。那么我如何告诉骆驼停止呢?让我们尝试将“ handled”设置为true吗?

<onException redeliveryPolicyRef="msRedeliveryPolicy">
    <exception>java.lang.Exception</exception>
    <redeliveryPolicy logRetryAttempted="true" retryAttemptedLogLevel="WARN"/>
    <handled><constant>true</constant></handled>
</onException>  

没有运气。仍然3秒。显然,甚至还没有到达重新交付部分。

有什么秘诀?

1 个答案:

答案 0 :(得分:1)

事实是端点中发生的错误没有由用户定义的路由处理(即上述设置中的fetchFiles)。因此,onExceptionredeliveryPolicy不涉及,因为它们仅影响属于用户定义路线的东西。

要控制从端点定义的使用者的行为,显而易见的方法是使用该组件中存在的选项。根据@Screwtape的建议,在您的情况下使用backoffErrorThresholdbackoffMultplier

为什么参数repeatCount在文档中存在,但无效使用?它可能在您的骆驼版本中不存在,并且Camel文档编写者忘记在文档中标记第一个存在的版本。

相关问题