Open cer opened 2 years ago
See LocalExceptionCreateOrderSaga for example usage.
Define Spring @Beans
that implement the following interface:
interface LocalStepExceptionHandler<E extends Exception, SagaData> extends Ordered {
void handleException(E e, SagaData sagaData);
}
If a local step throws an exception, the first (sorted by Ordered
) applicable - to exception and saga data - is invoked to update the SagaData
prior to starting compensation.
Current behavior
If a local step throws an exception the saga is rolled back.
Application code, e.g.
onSagaRolledBack()
does not have access to the exception and so cannot doesn't know the reason.Also, the rollback occurs for any exception, not just 'business-related' exceptions. Consequently, a transient technical failure will result in a rollback
Proposal
onException()
is the equivalent of a try-catch that updates the saga data with the reason for the error. Note: an exception can't be simply stored in the saga data because of the requirement to (de)serialize to/from JSONonExceptionRollback()
onExceptionRollback()
is not used, then all exceptions cause a rollback (original behavior)