简体   繁体   中英

Apache Camel: errorHandler vs onException?

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?

The errorHandler is used to handle any uncaught Exception that gets thrown during the routing and processing of a message. Conversely, onException is used to handle specific Exception types when they are thrown. Check out this article to see how to use onException .

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(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM