Apache Camel- Message Redelivery happens before onexception block executes

两盒软妹~` 提交于 2019-12-25 07:53:47

问题


Have the following camel route.

@Override
public void configure() throws Exception {

onException(java.lang.Exception.class).useOriginalMessage()
.beanRef("discoveryService", "updateConnection")
.redeliveryPolicyRef("redeliverMessagePolicy");

from(ENDPOINT_URI).to(queueName);
}

with Redelivery policy defined as following in xml-

<redeliveryPolicyProfile id="redeliverMessagePolicy"
    retryAttemptedLogLevel="WARN" maximumRedeliveries="8"
    redeliveryDelay="${redeliveryDelay}" />

However when an exception is thrown the redelivery attempts are made before the OnException block is executed(Some configuration properties get updated in the onException block. Have a debug point in DiscoveryService inside Onexception, it gets called after the redelivery attempts are made). Thus the current message gets lost without being redelivered. Not sure why this happens. Using activemq-camel version 5.8.0 Thnks


回答1:


Yes this is intended, the onException block is only executed when the exchange is exhausted (eg after all redelivery attempts have failed).

Read more about how error handling in Camel works in the docs

  • http://camel.apache.org/error-handling-in-camel.html

And if you have a copy of the Camel in Action book it has an entire chapter devoted to cover all about error handling (most complete documentation there is)

If you want to do some custom logic before each redelivery, then use the onRedelivery processor: http://camel.apache.org/exception-clause.html



来源:https://stackoverflow.com/questions/35331244/apache-camel-message-redelivery-happens-before-onexception-block-executes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!