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

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

问题描述

我在处理多条路由之间的异常时遇到了一些问题.

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

作为java开发者的角度,我想提取一些通用的逻辑到一个通用的路由中,这样其他路由就可以直接调用通用的路由,而不用到处都包含通用的逻辑.(比如route-version函数调用)但是当它来的时候对于错误处理,我发现它有点棘手.

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

问题是当从mock:commonlogic"端点抛出一些异常时,该异常不会被 doTry...doCatch 块在 route1 和 route2 中定义.似乎异常只能在公共路由范围内处理.但我想要的是公共路由只是抛出"异常,而调用者"路由自己处理这一切.有没有办法做到这一点?

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?

谢谢

推荐答案

您需要禁用公共路由中的错误处理.然后从公共路由抛出的任何异常都不会被任何错误处理程序处理,并传播回调用者路由,其中​​包含 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天全站免登陆