Camel - Exception handling in 'sub routes'

别来无恙 提交于 2019-12-20 19:43:12

问题


Camel explicitly handles two 'scopes' of error handling:

  • Global
  • per Route

The issue I'm having is exceptions thrown in a 'sub route'. For instance, I've got this route:

from("direct:sendToWebservice").
    .processRef("massageBeforeSending").
    .to("http://webservice.com").
    .processRef("massageResponse");

Then I've got two other routes that need to send messages to the webservice:

from(direct:fromSystemA").
    .errorHandler(deadLetterChannel("direct:TellSystemA")).
    .to("direct:sendToWebservice");

from(direct:fromSystemB").
    .errorHandler(deadLetterChannel("direct:TellSystemB")).
    .to("direct:sendToWebservice");

What I would like to happen is, if the webservice route throws an exception, it's propagated up to the caller, and either system A or system B would be notified. I don't see a way to achieve this.

I feel like this would be a common use case - has anyone bumped up against it before?

Thanks again for your time,

Roy


回答1:


Got the answer from a colleague: The subroute needs to have it's error handling disabled:

from("direct:sendToWebservice").
    .errorHandler(noErrorHandler())     // disables error handling for this route
    .processRef("massageBeforeSending").
    .to("http://webservice.com").
    .processRef("massageResponse");

This forces Camel to propagate the error to the calling route.



来源:https://stackoverflow.com/questions/7407105/camel-exception-handling-in-sub-routes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!