有以下 Camel 路线。
@Override
public void configure() throws Exception {
onException(java.lang.Exception.class).useOriginalMessage()
.beanRef("discoveryService", "updateConnection")
.redeliveryPolicyRef("redeliverMessagePolicy");
from(ENDPOINT_URI).to(queueName);
}
重新投递策略在 xml 中定义如下-
<redeliveryPolicyProfile id="redeliverMessagePolicy"
retryAttemptedLogLevel="WARN" maximumRedeliveries="8"
redeliveryDelay="${redeliveryDelay}" />
但是,当引发异常时,会在执行 OnException block 之前进行重新传递尝试(某些配置属性会在 onException block 中更新。在 OneException 内的 DiscoveryService 中有一个调试点,在进行重新传递尝试后会调用它) 。因此,当前消息会丢失而不会被重新传递。不知道为什么会发生这种情况。 使用activemq-camel版本5.8.0 谢谢
最佳答案
是的,这是有意的,onException block 仅在交换耗尽时执行(例如,在所有重新传递尝试都失败之后)。
在文档中详细了解 Camel 中的错误处理如何工作
如果您有《Camel in Action》一书的副本,其中有一整章专门介绍有关错误处理的所有内容(这是最完整的文档)
如果您想在每次重新投递之前执行一些自定义逻辑,请使用 onRedelivery
处理器:http://camel.apache.org/exception-clause.html
关于java - Apache Camel-消息重新传递发生在异常 block 执行之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35331244/