JOliver EventStore 快照
假设我有这段代码:
private void CreateSnapshots(IEnumerable<StreamHead> streams)
{
foreach (StreamHead head in streams)
{
IAggregate aggregate = ???;
IMemento memento = aggregate.GetSnapshot();
var snapshot = new Snapshot(head.StreamId, head.SnapshotRevision + 1, memento);
eventStore.AddSnapshot(snapshot);
observer.Notify(new SnapshotTaken(head.StreamId, head.HeadRevision));
}
}
我如何知道要为当前流加载什么聚合?我也在使用 CommonDomain。里面有东西吗?
谢谢
Say I have this code:
private void CreateSnapshots(IEnumerable<StreamHead> streams)
{
foreach (StreamHead head in streams)
{
IAggregate aggregate = ???;
IMemento memento = aggregate.GetSnapshot();
var snapshot = new Snapshot(head.StreamId, head.SnapshotRevision + 1, memento);
eventStore.AddSnapshot(snapshot);
observer.Notify(new SnapshotTaken(head.StreamId, head.HeadRevision));
}
}
how do I know what aggregate to load for the current stream? I'm also using CommonDomain. Is there something in there?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EventStore 的快照方面需要一点关爱。我尝试使 IStoreEvents 接口适合与单个聚合一起使用。我还尝试确保快照不会干扰或妨碍正常使用。
自 v2.0 发布以来,我现在将注意力转向 v2.1,并且我将能够进行一些与此相关的小的 API 更改。同时,您最好的选择可能是在进行快照时完全绕过 IStoreEvents。
另一种选择是让快照代码与常规代码一起在进程内运行。当加载聚合需要快照时,您可以轻松地将对该聚合的引用异步推送到快照代码。通过这种方式,您实际上不必执行加载,因为您已经拥有了聚合。
The snapshotting aspect of the EventStore needs a bit of love. I have tried to make the IStoreEvents interface geared toward working with an individual aggregate. I have also tried to ensure that snapshotting does not interfere or get in the way of normal use.
Since the release of v2.0, I have now turned my attention toward v2.1 and I will be able to make a few small API changes related to this. In the meantime, your best option is probably to bypass IStoreEvents altogether when doing snapshotting.
Another alternative is to have the snapshotting code run in-process with your regular code. When an aggregate is loaded the needs a snapshot, you could easily push a reference to that aggregate asynchronously to your snapshotting code. In this way, you don't actually have to do a load because you already have the aggregate.
我找到了一个适合我的解决方案(这绝对是一个黑客)。它仍然是带外快照。这是一个示例。
I found a solution for me (this is most definitely a hack). It is still out-of-band snapshotting. Here's a sample of it in action.