Wednesday, 18 July 2012

Spring Integration Exception Handling

Sooner or later you're going to have to deal with exceptions, it's essential that you understand exactly how they work, yet the Spring Integration documentation is fairly lightweight in this area.  Start by reading this as many times as it takes to sink in:  Error Handling

Understand the key differences between direct and asynchronous communication:
  1. With direct channels there is no hand-off between threads, the functionality is all handled in the same thread and exceptions (wrapped in a MessageHandlingException) are propagated and caught as usual
  2. Asynchronous commmunication - for example a queue channel - involves multiple threads, this creates complexity like how to pass back exceptions and transaction management (the standard transaction context is thread bound).  To handle the asynchronous exception problem SI wraps the exception in an ErrorMessage and places it on an error channel (again read the Error Handling link to understand which error channel it will choose).  You can call getPayload() and generally cast the result to a MessagingException.

No comments:

Post a Comment