具有多个RouteBuilder的camel中的错误处理

时间:2017-08-16 09:59:51

标签: java error-handling apache-camel camel-jms

我正在尝试处理由3个RouteBuilder组成的骆驼路线上的异常。主路由(调用其他路由)由jms队列触发,我想处理第一条路由上的所有异常。

主要路线:

    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");

第二条路线(由主路线呼叫。呼叫第三条路线和持续数据):

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}")

第二个被调用的路由(进行http GET调用并执行映射操作):

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}");

我捕获所有异常并将其包装在我的对象“SystemErrorException”中。 onException处理程序是:

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");

问题是当发生异常时,camelRedeliveryCounter始终为1,异常处理程序将进入无限循环重试。 有什么建议吗?

0 个答案:

没有答案