I'm writing an exercise application using DDD principles in java with spring boot and mongodb. According to DDD, the communication between Aggregates occur only through messaging. At this point Im not distributing the application, all aggregates resides in the same application, so Im simply using the Spring messaging capabilities to exchange messages.
Each aggregate correspond to exactly one mongo document. Each command or operation triggered by an event is guarded by a @Transactional annotation to ensure that the db transaction and the event are processed atomically.
I was wondering where should I store the events? Can I store them within the mongo document? Actually, since mongo transactions spans single documents, isn't this the only option?
Next step is to set a periodic task that will read all recent events and publish them to simulate an off thread communication. At this point, probably a good place would be a separate document collection storing the events.
P.S. I'm not taking event sourcing into consideration for the moment, as it seems to be more advanced.
Thank you!
question from:
https://stackoverflow.com/questions/65946218/ddd-and-messages-for-aggregates-communication 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…