CQRS: Storing events and publishing them - how do I do this in a safe way?

前端 未结 1 1161
名媛妹妹
名媛妹妹 2020-12-13 01:37

As I\'ve learned in Why is the CQRS repository publishing events, not the event store? it\'s the CQRS repository\'s task to publish events. So far, so good.

Of cours

相关标签:
1条回答
  • 2020-12-13 02:01

    Your repository could publish events, it doesn't have to. The solution in this case is to use the event store as a queue. You would have a background process that monitors the event store for new events, publishes them to (for instance) a bus, and then marks them as dispatched.

    As always, there are trade-offs. You'll likely have to deal with at-least-once messaging and idempotent processing. It's more complex than using a simple distributed transaction.

    Jonathan Oliver has written several posts about this topic that might help you out: Removing 2PC, How I Avoid Two-Phase Commit, Idempotency Patterns

    0 讨论(0)
提交回复
热议问题