java Apache Camel:errorHandler 与 onException?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17346581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 01:44:57  来源:igfitidea点击:

Apache Camel: errorHandler vs onException?

javaexception-handlingerror-handlingapache-camel

提问by Keith

What's the difference between:

有什么区别:

<camel:errorHandler id="deadLetterErrorHandler" type="DeadLetterChannel" 
        deadLetterUri="log:dead">

<camel:camelContext errorHandlerRef="deadLetterErrorHandler">
    ...
</camel:camelContext>

And:

和:

<onException>
    ...
</onException>

According to this article, using them both in conjunction is a "powerful combination". How so? What roles do they each individual assume, and how do they complement each other?

根据这篇文章,将两者结合使用是一种“强大的组合”。怎么会这样?他们每个人承担什么角色,他们如何相互补充?

回答by Keith

The errorHandleris used to handle any uncaught Exceptionthat gets thrown during the routing and processing of a message. Conversely, onExceptionis used to handle specific Exceptiontypes when they are thrown. Check out this articleto see how to use onException.

errorHandler被用来处理任何未捕获Exception该获取消息的路由和处理过程中抛出。相反,onException用于Exception在抛出特定类型时处理它们。查看本文以了解如何使用onException.

回答by SMS Krishnan

If the action you need to perform for each type of exception is different, use onException. It lets you define error handling on a per exception basis.

如果您需要对每种类型的异常执行的操作不同,请使用 onException。它允许您在每个异常的基础上定义错误处理。

onException(xxxException.class).to("activemq:xxxFailed");onException(yyyException.class).to("activemq:yyyFailed");

onException(xxxException.class).to("activemq:xxxFailed");onException(yyyException.class).to("activemq:yyyFailed");

If you just need a generic handler, go with errorHandler. For all type of errors, the same processing will be performed.

如果您只需要一个通用处理程序,请使用 errorHandler。对于所有类型的错误,将执行相同的处理。