alexanderific
alexanderific

Reputation: 790

How to configure Camel's RedeliveryPolicy retriesExhaustedLogLevel?

I have set up an errorHandler in a Camel route that will retry a message several times before sending the message to a dead letter channel (an activemq queue in this case). What I would like is to see an ERROR log when the message failed to be retried the max number of times and was then sent to the dead letter queue.

Looking at the docs for error handling and dead letter channels, it seems that there are 2 options available on the RedeliveryPolicy: retriesAttemptedLogLevel and retriesExhaustedLogLevel. Supposedly by default the retriesExhaustedLogLevel is already set at LoggingLevel.ERROR, but it does not appear to actually log anything when it has expended all retries and routes the message to the dead letter channel.

Here is my errorHandler definition via Java DSL.

.errorHandler(this.deadLetterChannel(MY_ACTIVE_MQ_DEAD_LETTER)
    .useOriginalMessage()
    .maximumRedeliveries(3)
    .useExponentialBackOff()
    .retriesExhaustedLogLevel(LoggingLevel.ERROR)
    .retryAttemptedLogLevel(LoggingLevel.WARN))

I have explicitly set the level to ERROR now and it still does not appear to log out anything (to any logging level). On the other hand, retryAttemptedLogLevel is working just fine and will log to the appropriate LoggingLevel (ie, I could set retryAttemptedLogLevel to LoggingLevel.ERROR and see the retries as ERROR logs). However I only want a single ERROR log in the event of exhaustion, instead of an ERROR log for each retry when a subsequent retry could potentially succeed.

Maybe I am missing something, but it seems that the retriesExhaustedLogLevel does not do anything...or does not log anything if the ErrorHandler is configured as a DeadLetterChannel. Is there a configuration that I am still needing, or does this feature of RedeliveryPolicy not execute for this specific ErrorHandlerFactory?

I could also set up a route to send my exhausted messages that simply logs and routes to my dead letter channel, but I would prefer to try and use what is already built into the ErrorHandler if possible.

Upvotes: 0

Views: 2010

Answers (2)

shijin raj
shijin raj

Reputation: 91

Please try with this code:

.errorHandler(deadLetterChannel("kafka:sample-dead-topic")
                .maximumRedeliveries(4).redeliveryDelay(60000)
                .retriesExhaustedLogLevel(LoggingLevel.WARN)
                .retryAttemptedLogLevel( LoggingLevel.WARN)
                                .retriesExhaustedLogLevel(LoggingLevel.ERROR)
                .logHandled(true)
                .allowRedeliveryWhileStopping(true)
                .logRetryStackTrace(true)
                .logExhausted(true)
                .logStackTrace(true)
                .logExhaustedMessageBody(true)
        )

retry is configured for 1 minute interval.

Camel application logged the errors for evry retry with the detailed information.

Upvotes: 0

alexanderific
alexanderific

Reputation: 790

Updated the ErrorHandler's DeadLetterChannel to be a direct endpoint. Left the 2 logLevel configs the same. I got the 3 retry attempted WARN logs, but no ERROR log telling me the retries were exhausted. I did, however, set up a small route listening to the direct dead letter endpoint that logs, and that is working.

Not a direct solution to my desire to have the ERROR log work for the exhaustion, but is an acceptable workaround for now.

Upvotes: 1

Related Questions