简体   繁体   English

apache-camel错误处理程序范围说明

[英]apache-camel error handler scope clarification

Below is an example route take from Camel In Action book. 以下是《骆驼在行动》一书中的路线示例。 There is one error handler at context scope and two route definitions. 在上下文范围内有一个错误处理程序,并且有两个路由定义。 My questions 我的问题

  1. Is it correct to say that the context level error handler is applicable only for Route 1? 说上下文级别错误处理程序仅适用于路由1是否正确?
  2. Does the dead letter error handler kick in for any exceptions thrown from any of the steps in route 2. ie from orderService.validate() and orderService.enrich() . 死信错误处理程序是否会引发路线2中任何步骤orderService.validate()即,来自orderService.validate()orderService.enrich()引发的任何异常。
  3. What if I want different error handler for exceptions that arise from validate() and enrich() methods? 如果我想要不同的错误处理程序来处理来自validate()enrich()方法的异常怎么办?

    //context scope error handler //上下文范围错误处理程序

     errorHandler(defaultErrorHandler() .maximumRedeliveries(2) .redeliveryDelay(1000) .retryAttemptedLogLevel(LoggingLevel.WARN)); //Route 1 from("file://target/orders?delay=10000") .beanRef("orderService", "toCsv") .to("mock:file") .to("seda:queue.inbox"); //Route 2 with route scope error handler from("seda:queue.inbox") .errorHandler(deadLetterChannel("log:DLC") .maximumRedeliveries(5).retryAttemptedLogLevel(LoggingLevel.INFO) .redeliveryDelay(250).backOffMultiplier(2)) .beanRef("orderService", "validate") .beanRef("orderService", "enrich") .to("mock:queue.order"); 

your assumptions on #1 & #2 are correct... 您对#1和#2的假设是正确的...

for #3, either define Exception Clauses to catch explicit exceptions thrown by your bean methods (OrderValidateException, EnrichException, etc.) or use inline try-catch blocks around each step in your route (I prefer the first approach myself) 对于#3,要么定义“ 异常子句”以捕获由bean方法抛出的显式异常(OrderValidateException,EnrichException等),要么在路由的每个步骤周围使用内联try-catch块(我更喜欢第一种方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM