Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backoff not working in Apache Camel redelivery

(Camel version 2.14.1)

I'm trying to get Camel to retry a msg to JMS (actually, MQ over JMS) using a backoff redelivery policy. Here's what I've got:

errorHandler(defaultErrorHandler()
    .maximumRedeliveries(-1) 
    .useExponentialBackOff()
    .backOffMultiplier(2)
    .maximumRedeliveryDelay(30000)
    .retryAttemptedLogLevel(LoggingLevel.WARN));

from("direct:in")
    .log("Sending message to MQ")
    .to("mq:MY_QUEUE?requestTimeout=1000");

My understanding of what should happen here is that the initial timeout will be 1000ms. After that camel will wait 2000ms, then 4000ms, etc, until we get to 30000ms.

What's happening is that the message is retried, but at 1000ms every time.

What might I need to change in my code above to get the results that I'm looking for?

TIA

like image 751
Roy Truelove Avatar asked Oct 20 '22 04:10

Roy Truelove


1 Answers

Figured this out.

Here are the available configuration parameters that come into play (there are a lot).

On the error handler:

defaultErrorHandler()
    .maximumRedeliveries(-1) 
    .useExponentialBackOff()
    .backOffMultiplier(2)
    .maximumRedeliveryDelay(10000)
    .redeliveryDelay(500)

On the URI:

requestTimeout=400&
requestTimeoutCheckerInterval=300

There are a few scenarios here that act very differently

Scenario A) JMS Server is down.

If the server is down then the fields from the URI (requestTimeout and requestTimeoutCheckerInterval) never come in to play. Using the settings above you should see a retry delays of: 500, 1000, 2000, 4000, 8000, 10000, 10000, 10000...

Scenario B) JMS Server is up but consumer on the other side has not responded.

The requestTimeout value is never increased but the retry delay is. So what you'll see is retry delays at: 900, 1400, 2400, 4400, 8400, 10400, 10400, 10400....

Why? Because it takes 400ms (the requestTimeout to actually fail, after which the errorHandler timer kicks in).

Gotchas !!!

  • This little doozy here which is a log msg from a *MessageListenerContainer:

Could not refresh JMS Connection for destination 'REPLY.A.QUEUE' - retrying using FixedBackOff{interval=5000, currentAttempts=67, maxAttempts=unlimited}

This has nothing to do with retrying a message, it happens in another thread. That FixedBackOff thing is a red herring.

  • requestTimeoutCheckerInterval must always be <= requestTimeout or else the timeout will seemingly happen later than it's supposed to
like image 90
Roy Truelove Avatar answered Nov 11 '22 17:11

Roy Truelove