这是一个简化的 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
)。因此,onException
和 redeliveryPolicy
不涉及,因为它们只影响属于用户定义路由的内容。
要控制端点中定义的消费者的行为,明显的方法是使用该组件中存在的选项。根据@Screwtape的建议,针对您的情况使用 backoffErrorThreshold
和 backoffMultplier
。
为什么doc中存在参数repeatCount
,但无法使用?它可能不存在于您的 Camel 版本中,并且 Camel 文档编写器忘记标记文档中的第一个存在版本。
关于java - Camel 延迟会覆盖任何重新投递策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58855052/