English 中文(简体)
如何处理多路线的例外或过失
原标题:how to handle exception or fault in multiple routes

我在处理多条路线之间的例外时有些问题

作为 Java 开发者的观点, 我想为一条共同路线提取一些共同的逻辑, 这样其他路线可以直接调用共同路线, 而不包含所有地方的共同逻辑。 (像路线转换函数调用) 但是当涉及到错误处理时, 我发现它有点棘手。

例如:

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

问题在于从“ 模拟: 共通” 终点扔出一些例外, 例外不会被在路线1 和路线2 中定义的 doCatch 区块所抓住。 这似乎只是可以在共同路线范围内处理例外。 但我想要的是共同路线只是扔出例外,而呼叫者路线自己处理。 有没有办法做到这一点?

谢谢 谢谢

最佳回答

您需要在共同路径中禁用错误处理 。 那么从共同路径中丢弃的任何例外, 则不由任何错误处理者处理, 并传播回呼叫路径, 即尝试.... catch block 。

from("direct:common")
   .errorHandler(noErrorHandler())
   .to("mock:commonlogic")
问题回答

You might want to use the exception clause. http://camel.apache.org/exception-clause.html

像这样(在路由构建器配置方法中)

// A common error handler for all exceptions. You could also write onException statements for explicit exception types to handle different errors different ways.
onException(Exception.class).to("log:something"); 

from("direct:route1")...;

from("direct:route2")...;

它应该为你做这个把戏。

对当前路由建设器来说,例外将是全球性的。





相关问题
Creating JMS Queues at runtime [closed]

I am working on an application where the app user can create / delete queues . Also , he would be able to move a message from 1 queue to another, delete a message , rearrange the messages in the ...

Extending ManagedPerformanceCounter

I have been trying to add my own performance counter, and I m unable to use this performance counter for my routes. Could anyone tell me how to use a custom performance counter instead of ...

Apache Camel with ActiveMQ clustering

I m trying to determine my options for clustering my ServiceMix 3.3.1/Camel 2.1/AMQ 5.3 application. I m performing high volume message processing and I need to cluster for high availability and ...

Using Camel 2.1 with Grails 1.2.1 - Classloading problem

I m trying to define a Camel context in my Grails application. resource.groovy: xmlns camel: http://camel.apache.org/schema/spring camel { camelContext(id: camelContext ) { } } Results ...

Apache camel without maven

I have a hard time finding documentation/tutorials or just getting a dependency overview without going into some spiralling maven-nightmare. I even have trouble getting the examples to work, as its ...

CamelContext.start() doesn t block

I want to run a simple Apache Camel example that copies files from one directory to another: CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { public void ...

热门标签