问题
Heres what Im thinking. Do you see any issues with this workaround to emulate 2 phase commit when using something like MongoDB where each operation is atomic and there is no support for transactions outside of that?
transaction_scope:
read message from servicebus - UpdateCustomerAddress
get customer aggregate from docdb, replay events where commited =1
call customer.updateAddress
validates
creates customer address updated event
apply event
event store as uncommitted events
do optimistic concurrency update against docdb pushing uncommitted events (single op to ensure consistency)
publish event to service bus
update docdb set events just published to commited = 1 (again one 1 op - at least in mongodb)
transaction_complete
NServiceBus or whatever manages outer transaction scope from the command handler infrastucture. From what I see we should have near same semantics of 2pc - but I feel Im missing something.
回答1:
A two-phase commit wiki page has recently been added to the mongodb website. It describes the 2-PC algorithm and discusses a few failure scenarios.
来源:https://stackoverflow.com/questions/2716582/two-phase-commit-with-mongodb