我正在尝试处理由 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,并且异常处理程序进入无限循环重试。有什么建议么?