Apache Camel- Message Redelivery happens before on

2019-09-05 02:40发布

问题:

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