Catch exception strategy documentation
This exception strategy should be used when despite an error occurred you still consider that the message was consumed successfully. It can be used by placing <catch-exception-strategy> element at the end of the flow. It's similar to a catch block in java that never re-throws exceptions.
Example use cases
Use case: You have to provide JSON style services through HTTP endpoint. If everything goes fine the you send back to the caller a JSON response. But if while processing a message an exception was thrown then you want to send back a JSON error message with information about the failure.
Configuration:
This flow configures an HTTP inbound endpoint where the messages are going to be received. Then it transform the JSON message to a JsonRequest object, process the request and transform back the result to a JSON message to be sent back to the client. In case that an exception is thrown then <catch-exception-strategy> will take action and it will process the exception, convert back the payload object to a JSON message and return it to the caller.
Use case: You need to consume a message from a JMS queue, enrich them message adding a property to it with some information from an external source and put it in another queue. The information that you must add to the message is no so critical so in case flow execution fails during enrichment you can add a the same property but with constant value letting know that information is not available.
Configuration:
This flow it's trying to consume a reservation message for a trip and add a header to it with information about seats. If something fails while retrieving seats information, then puts another header with information about seats not available. Message will be consumed in either case.
Catch exception strategy behavior
These are the steps executed by <catch-exception-strategy>
- Log exception
- Starts execution with the message at the time of the exception
- Set message.exceptionPayload attribute with DefaultExceptionPayload using exception thrown
- Routes message through configured message processors
- Close payload open stream if available
- Commit transaction if available
- Resume any XA suspended transaction
- Nullify message.exceptionPayload
- Return event processing result of executing exception strategy