0

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?

  • http://camel.apache.org/exception-clause.html. Global scope for Java DSL is per RouteBuilder instance, so if you want to share among multiple RouteBuilder classes, then create a base abstract RouteBuilder class and put the error handling logic in its configure method. And then extend this class, and make sure to class super.configure(). We are just using the Java inheritance technique. Have you try this way? – Manwlis.e Aug 16 '17 at 10:24
  • This resolve the problem of infinite loop but add another one. I want to mantain the message on "OSAPI.EVENT.NOTIFICATION.IN.D" main queue until success or user decide to skip this message (with another api), but this make 3 redelivery and then call another "default error handling" that make 6 retries (tot 24 redeliveries 6x4), after this the message was deleted from main queue and moved on default dead letter queue. Can I disable default dead letter error handler? – Elia Zoffoli Aug 16 '17 at 11:35
  • Without being sure if you want to maintain the message on the first queue until success you might need transactions http://camel.apache.org/transactional-client.html . Keep in mind that " The redelivery in transacted mode is not handled by Camel but by the backing system (the transaction manager). In such cases you should resort to the backing system how to configure the redelivery." But i haven't test this or i don't know what code changes you have made. – Manwlis.e Aug 16 '17 at 11:51
  • Ok. The problem was activeMQ. I didn't know that activeMQ have redelivery max set to 6 retries. I've modified activeMQ policy and now it work. Thanks – Elia Zoffoli Aug 16 '17 at 14:21

0 Answers0