Event Sourcing: Events that trigger others & rebuilding state

前端 未结 3 1574
借酒劲吻你
借酒劲吻你 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条回答
  •  梦毁少年i
    2021-02-04 08:07

    You should not raise event from event handler - just don't do it! You should use sagas instead.

    In your case, saga subscribes for PurchaseMadeEvent and issues PromoteCustomer COMMAND, which causes to happen CustomerPromoted event. Again, there is another saga that subscribes for CustomerPromoted event and sends SendEmailToPromotedCustomer command. When you are replaying events - just don't subscribe saga for CustomerPromoted event.

    This is all about the difference between command and event. It is important to understand it. Events tell what already has happened, commands tell what will happen.

提交回复
热议问题