Event Sourcing: Events that trigger others & rebuilding state

前端 未结 3 1573
借酒劲吻你
借酒劲吻你 2021-02-04 07:26

I\'m struggling to get my head around what should happen when rebuilding the model by replaying events from the EventStore, in particular when events may trigger other events t

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 07:51

    Events chaining can be very tricky and easily run out of control, so I'd avoid it as much as possible. For example in the scenario you're describing I'd raise a UserPromotedEvent (maybe even using the PromoteUserCommand), however I wouldn't consider actual/physical sending of an email as part of my domain. Instead I would create additional handler/denormalizer for UserPromotedEvent that would register the need of sending the email with some additional checks quite possibly. After that another process would gather information of not yet processed emails and send them. This approach would mitigate the problems that might occur with not fully accessible/scalable email gateway.

    In more general - the need of events chaining very often indicates that you should consider implementing a Saga for the process.

提交回复
热议问题