I'm trying to handle exceptions on my camel route that is composed of 3 RouteBuilder. The main route (that call the others) is triggered by jms queue, and I want to handle all the exceptions on this first route.
Main Route:
from("jmsadp:queue:OSAPI.EVENT.NOTIFICATION.IN.D?acknowledgementModeName=CLIENT_ACKNOWLEDGE")
.routeId("OSAPI.EVENT.NOTIFICATION.IN.D.DEQUEUE")
.log("${header.JMSRedelivered}")
.log("Generic route start")
.log("${body}")
.log("EventID in header is: ${header.EventID}")
.log("EventNotificationType in header is: ${header.EventNotificationType}")
.filter(header("EventNotificationType").regex("(?i)hr"))
.log("Entered in idemtpotence")
.idempotentConsumer(header("EventID"), jdbcMessageIdRepository)
.log("Exited from idempotence")
.log("Processor that deserialize json")
.process("mexToObjProc")
.to("direct:hr_orchestrator");
Second route (called by main route. Call third route and persinst data):
from("direct:hr_orchestrator")
.errorHandler(noErrorHandler())
//per permettere la gestione degli errori alla rotta generica
.log("started hr_orchestrator route")
.log("${body}")
.setExchangePattern(ExchangePattern.InOut)
.to("direct:ihcm-worker_personalAddress_change")
.log("${body}")
.log("processor that persist event and info on db")
.process("persistEventObjProcessor")
.log("${body}")
Last route called by second (Make a http GET call and do mapping operations):
from("direct:ihcm-worker_personalAddress_change")
//per permettere la gestione degli errori alla rotta generica
.errorHandler(noErrorHandler())
.log("dynamic route that get event info")
.log("${body}")
.log("process that call iHCM API")
.process(new ChangeAddressRequestProcessor())
.log("${body}")
.log("process that map iHCM object to custom object")
.process(new ChangeAddressMappingProcessor())
.log("${body}");
I catch all exceptions and I wrap it in my object "SystemErrorException". The onException handler is:
onException(SystemErrorException.class)
.log("Gestione eccezioni MainHRRoute")
.log("camelRedeliveryCounter: ${header.camelRedeliveryCounter}")
.log(LoggingLevel.ERROR, "${body}")
.log(LoggingLevel.ERROR, "${exception.message}")
.log(LoggingLevel.ERROR, "${exception.stacktrace}")
.maximumRedeliveries(3)
.handled(false)
//Processor that check camelRedeliveryCounter in header and
//interrupt queue consumer.
.onExceptionOccurred(new ErrorHandlerProcessor())
.to("jmsadp:queue:OSAPI.EVENT.NOTIFICATION.ERRORS.D");
The problem is that when exception occur camelRedeliveryCounter have always value 1, and the exception handler go to infinite loop retry. Any suggestions?