问题
Me and my team currently work on the read side of a CQRS and event-sourcing system. We want our projectors to be able to listen to only a subset of all events and we want our projectors to be idempotent since an event can be published many times. Here is our current architecture:
Since a projectionist doesn't handle all events how it can know if an event hasn't been received in the correct order or if an event has already been received? We can't use the sequence number because the sequence number is related to a stream and not an event type.
The terms "projectionist", "projection ledger" and "projector" comes from this article.
回答1:
How to know if we have to reorder/ignore events on read side?
The "Bus" is not the authority for order of events - that responsibility lies with the event store. So a projectionist that needs to know what order things happen should query the store, rather than trying to reconstruct the original ordering from the information on the bus.
Greg Young's 2014 talk Polyglot Data includes a good discussion of this point.
(The projectionist might query the event store via some API, rather than talking to the store directly - a curated atom feed based on the data in the store).
回答2:
Like proposed by @VoiceOfUnreason, we fixed the problem by ditching the bus and by replacing it with the change feed processor of CosmosDB since our events are stored in CosmosDB. We had no problem with this solution so far. The change feed processor is capable of managing the checkpoints and broadcasting the events to every projectors out of the box!
来源:https://stackoverflow.com/questions/56150852/cqrs-es-how-to-know-if-we-have-to-reorder-ignore-events-on-read-side