Of course, it depends on how you decide to implement your system.
Here you can consider several options:
1. Two-phase acceptance When performing two-phase commit, basically each handler contains 3 methods: one for Preparing, one for committing and one for rolling back.
For all event handlers, Prepare is first created. If none of these reports is a problem, all Commit () methods of the handlers are called. If any of these reports causes a problem - despite the absence of messages caused by Prepare () calls, then for all handlers whose Commit () has already been executed, you call their rollback () methods.
2. Internal and external event handlers Another option is to separate event handlers. You can post an event, such as UserCreated, which is handled by event handlers that take part in the transaction in the first place. The event is stored in the database as part of the transaction. Then you can have external event handlers that respond only to events that are already stored in the database - for example, the sender of the email. They can only be called after the initial transaction has been completed.
I'm sure you can come up with more ways to handle your specific scenario.
source share