When I publish CustomEvent in the end of @Transactional
and @Retryable(value = StaleStateException.class) method foo()
, how it is processed?
If I get StaleStateException
during commit after method execution, then @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
won't called and by @Retryable
Spring will call foo()
second time. And what is lifecycle of first CustomEvent
in this case? Will it be cleaned up? Or after second success call of foo()
,@TransactionalEventListener()
will be called twice?
If someone will meet the same worry, answer is that events listened by TransactionalEventListener are alive only transaction-time. RetryTemplate creates new transaction for every call of @Retryable method, so only events from successful attempt will arrive to @TransactionalEventListener.