When Atomic Behaviour Needed
- Transactional context will be held to the following function scope
- When any step here failed, the main transaction will be failed as well
1@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
2fun somethingHappenOn(event: SomeEvent)
When It can Fail Independently
- The following will be executed only when the transaction is committed
- Not only that, the
@Transactional
annotation provides next transactional context
- When we don't need any transaction (like sending email to the subscribed users), we can omit
@Transactional
1@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
2@Transactional(propagation = Propagation.REQUIRES_NEW)
3fun somethingHappenOn(event: SomeEvent)