java - Camel 延迟会覆盖任何重新投递策略

标签 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>

What do you think happens on failure? (Delay is 3 seconds, and redeliveryDelay is 10 seconds.)

Answer: It polls every 3 seconds, forever.

那么让我们看一下文档。也许我需要这个

"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 秒就会轮询一次。那么我该如何告诉 Camel 停止呢?我们尝试将“handled”设置为 true?

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

运气不好。还有3秒。显然还没有到达重新交付部分。

secret 是什么?

最佳答案

事实上,从端点发生的错误不是由用户定义的路由处理的(即上面设置中的fetchFiles)。因此,onExceptionredeliveryPolicy 不涉及,因为它们只影响属于用户定义路由的内容。

要控制端点中定义的消费者的行为,明显的方法是使用该组件中存在的选项。根据@Screwtape的建议,针对您的情况使用 backoffErrorThresholdbackoffMultplier

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

关于java - Camel 延迟会覆盖任何重新投递策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58855052/

相关文章:

JavaFX TitledPane lookup(.title) 返回 null

没有 matcher.find(),Java Regex : Why matcher. group() 不起作用?

java - 如何设置正确的Bean类路径

spring-boot - Autowiring 的 FluentProducerTemplate 在同一服务中使用之前是否需要清除其 header 和正文?

java - 如何将 XStream 引用传递给 Camel 进行编码

c# - 从 Java 到 C# 验证(匹配) token

java - 在java中运行一个方法最多预先指定或返回

java - 我如何或在哪里访问我的属性文件

java - 如何从 Apache Camel 调用带有 BODY 内容的 Rest API DELETE 操作?

transactions - ActiveMQ 是否支持多个事务性消费者?