问题
I developed a couple of E-Commerce sites, I noticed the axonframework recently. I'm considering how to implement an new E-Commerce site with axonframework.
I mean to use standard repositories to persist aggregates(in our case, they are orders) simply, but we also need the order history for review purpose. I wonder if we can use event Sourcing repositories to persist all event on an order to implement order history or not.
Questions:
- Can I use both standard repositories and event Sourcing repositories in axonframework?
- If I can use both standard repositories and event Sourcing repositories, how axonframework load an aggregate by identifier, is it done by standard repository or event Sourcing repository?
- Any suggest is appreciated.
Thanks in advance.
回答1:
In essence, you don't need Event Sourcing to be able to record all events from a system; you need an Event Store. In Axon, an Event Store is a specialized version of the Event Bus, which stores all Events in an EventStorageEngine (e.g. JPA, JDBC or Mongo) before publishing them to all listeners.
In respect to Repository, you can only use a single Repository to load an Aggregate. It's either Event Sourced, or it's not. When it's Event Sourced, the Aggregate is reconstructed using the Events that it published in the past. Otherwise, an ORM mechanism will reconstruct current state based on the data stored in the database.
来源:https://stackoverflow.com/questions/44511822/can-i-use-both-standard-repositories-and-event-sourcing-repositories-in-axonfram