NEventStore问题与重播事件 [英] NEventStore issue with replaying events

查看:72
本文介绍了NEventStore问题与重播事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用CQRS + ES。 ES是NEventStore(以下称为JOliver EventStore)。我们在不同的命令中有2个聚合。第二AR的投影取决于在读取模型中由第一AR投影写入的数据。问题在于,当我们运行该软件时,一切进展得如此之快,有时这两个聚合有时会以相同的日期时间(列CommitStamp)保留在事件存储中。重播事件时,我们从CommitStamp列开始的顺序开始获取它们。但是,如果两个流具有相同的CommitStamp并以错误的顺序处理,则读取的模型投影会出现异常。

We are using CQRS + ES. The ES is NEventStore (folrmerly JOliver EventStore). We have 2 aggregates in different commands. The projections of the second AR depends on the data written by the first AR projections in the read model. The problem is that when we run the software everything goes so fast that sometimes the two aggregates are persisted in the event store with identical datetime (column CommitStamp). When replaying the events we get them from the beginning ordered by CommitStamp column. But if the two streams are with identical CommitStamp and taken in wrong order the read model projections blow with exceptions.

有什么办法解决此问题吗?

Any idea how to solve this problem?

=============================

===============================

以下是有关此问题的讨论,位于github
https:// github.com/NEventStore/NEventStore/issues/170

Here is the discussion about this problem at github https://github.com/NEventStore/NEventStore/issues/170

=================== ==========

===============================

编辑:这是我们当前重播事件的方式。我搜索了GetFrom(...)的工作方式,结果发现commitstamp列未用于排序。毕竟没有提交顺序。因此,如果我开始重播事件,则可能会从今天开始返回一个事件,再返回2年前记录的事件,再返回等等。

EDIT: This is how we currently replay events. I searched how GetFrom(...) works and it turned out that commitstamp column is not used for ordering. After all there is not commit order. So if I start replaying events it may return an event from today, next an event recorded 2 years ago, next etc

public void ReplayEvents(Action<List<UncommittedEvent>> whatToDoWithEvents, DateTime loadEventsAfterDate)
    {
        var eventPortion = store.Advanced.GetFrom(loadEventsAfterDate);

        var uncommitedEventStream = new UncommittedEventStream();
        foreach (var commit in eventPortion)
        {
            foreach (var eventMessage in commit.Events.ToList()))
            {
                uncommitedEventStream.Append(new UncommittedEvent(eventMessage.Body));
            }
        }
        whatToDoWithEvents(uncommitedEventStream.ToList());
    }


推荐答案

Damian在其中添加了一个检查点列数据库。这在当前的master分支中。使用 GetFromCheckpoint(int)重播事件时,结果正确。

Damian added a checkpoint column in the database. This is in the current master branch. When the events a replayed with GetFromCheckpoint(int) the results are correct.

这篇关于NEventStore问题与重播事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆