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 course, storing the events and publishing them should be within one single transaction. Technically this means writing one (or more) records to the store, and publishing one (or more) events to a message bus. Hence, a simple database transaction is not enough, it should be a distributed one.
Now, unfortunately, many NoSQL databases (such as MongoDB) do not support ACID-compliant transactions, not even to talk of the possibility of taking place in a distributed transaction. More over, there are message queues out there that do not support distributed transactions as well.
So the question is: How do I deal with this?
Is there a recommended pattern to use?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…