如何处理多个路由异常或故障 [英] how to handle exception or fault in multiple routes

查看:200
本文介绍了如何处理多个路由异常或故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题,当处理多个路由之间的除外。

I have some problems when handle the exception between multiple routes.

作为一个Java开发人员的角度,我想提取一些共同的逻辑,一个共同的路线,这样其他途径可以直接调用常见的途径,而不处处包含常见的逻辑。(如路由版本的函数调用),但是,当涉及错误处理,我发现这是一个有点棘手。

As a java developer's perspective, I want to extract some common logic to a common route so that other routes can call the common route directly without containing the common logic everywhere.(like the route-version function call) But when it comes to the error handling, I found it's a little tricky.

例如:

//main logic 1
from("direct:route1")
  .doTry()
     .to("direct:common")
  .doCatch(Exception.class)
     .log("Error in route1")
  .end()

//main logic 2
from("direct:route2")
  .doTry()
     .to("direct:common")
  .doCatch(Exception.class)
     .log("Error in route2")
  .end()

//common logic
from("direct:common")
   .to("mock:commonlogic")

问题是,当从模拟:commonlogic抛出一些例外端点,该异常不会被两个在路径1和路径2中定义doTry ... doCatch块捕获。好像只是可以在公共范围的路由处理例外。但我想要的是常见的途径只是'抛出'例外和主叫方路线自行处理这一切。有没有办法做到这一点?

The problem is when some exception thrown from the "mock:commonlogic" endpoint, the exception won't be caught by doTry...doCatch blocks defined both in route1 and route2. It seems like the exception just can be handled in the common route scope. But what I want is the common route just 'throws out' the exception and the 'caller' routes handle it all by themselves. Is there any way to do that?

感谢

推荐答案

您需要禁用错误在公共route.Then处理从常见的途径抛出的异常,不被任何错误处理程序处理,并传送回来电者的路线,它具有在try ... catch块。

You need to disable error handling in the common route.Then any exceptions thrown from the common route, is not handled by any error handler, and propagated back to the caller route, which has the try .. catch block.

from("direct:common")
   .errorHandler(noErrorHandler())
   .to("mock:commonlogic")

这篇关于如何处理多个路由异常或故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆