11 Error handling

 

This chapter covers

  • Understanding error handling
  • Knowing where and when Camel’s error handling applies
  • Using the various error handlers in Camel
  • Using redelivery policies
  • Handling exceptions with onException
  • Reusing error handlers in all your routes
  • Performing fine-grained control of error handling

You’ve now reached the halfway mark of this book, and we’ve covered a lot of ground. But what you’re about to embark on in this chapter is one of the toughest topics in integration: how to deal with the unexpected.

Writing applications that integrate disparate systems is a challenge when it comes to handling unexpected events. In a single system that you fully control, you can handle these events and recover. But systems that are integrated over the network have additional risks: the network connection could be broken, a remote system might not respond in a timely manner, or it might even fail for no apparent reason. Even on your local server, unexpected events can occur, such as the server’s disk filling up or the server running out of memory. Regardless of which errors occur, your application should be prepared to handle them.

In these situations, log files are often the only evidence of the unexpected event, so logging is important. Camel has extensive support for logging and for handling errors to ensure that your application can continue to operate.

11.1 Understanding error handling

11.1.1 Recoverable and irrecoverable errors

11.1.2 Where Camel’s error handling applies

11.2 Using error handlers in Camel

11.2.1 Using the default error handler

11.2.2 The dead letter channel error handler

11.2.3 The transaction error handler

11.2.4 The no error handler

11.2.5 The logging error handler

11.2.6 Features of the error handlers

11.3 Using error handlers with redelivery

11.3.1 An error-handling use case

11.3.2 Using redelivery

11.3.3 Using DefaultErrorHandler with redelivery

11.3.4 Error handlers and scopes

11.3.5 Reusing context-scoped error handlers

11.4 Using exception policies

11.4.1 Understanding how onException catches exceptions

11.4.2 Understanding how onException works with redelivery

11.4.3 Understanding how onException can handle exceptions

11.4.4 Custom exception handling

11.4.5 New exception while handling exception

11.4.6 Ignoring exceptions

11.4.7 Implementing an error-handler solution

11.4.8 Bridging the consumer with Camel’s error handler

11.5 Working with other error-handling features