重播特定类型的事件

发布于 2024-11-24 21:06:24 字数 209 浏览 1 评论 0原文

我正在查看 joliver 的 EventStore 并考虑为新的事件处理程序重播事件。我看到有一种方法可以获取自某个时间点(ICommitStreams.GetFrom(Date))以来的所有提交,但我不知道如何仅获取特定类型的事件。

我错过了什么吗?

I'm looking at joliver's EventStore and thinking about replaying events for a new event handler. I see there's a method to get all the commits since a certain point in time (ICommitStreams.GetFrom(Date)) but I can't figure out how to only get events of a specific type.

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2024-12-01 21:06:24

仅供参考,这就是我所做的:

var typesToSend = typeof (MyApp.Messages.Events.SomeAggregate.SomeEvent).Assembly
    .GetTypes()
    .Where(t => t.Namespace != null && t.Namespace.StartsWith("MyApp.Messages.Events.SomeAggregate"))
    .ToList();

var commits = eventStore.Advanced.GetFrom(DateTime.MinValue)
    .Where(c => c.Events.Any(e => typesToSend.Contains(e.Body.GetType())))
    .OrderBy(c => c.CommitSequence)
    .ToList();

正如 Jonathan 所说,一次提交可能包含多个事件,这将获取包含至少一个我正在查找的事件的所有提交。要进一步过滤,您必须查看提交中的每个事件。

Just for reference, this is what I do:

var typesToSend = typeof (MyApp.Messages.Events.SomeAggregate.SomeEvent).Assembly
    .GetTypes()
    .Where(t => t.Namespace != null && t.Namespace.StartsWith("MyApp.Messages.Events.SomeAggregate"))
    .ToList();

var commits = eventStore.Advanced.GetFrom(DateTime.MinValue)
    .Where(c => c.Events.Any(e => typesToSend.Contains(e.Body.GetType())))
    .OrderBy(c => c.CommitSequence)
    .ToList();

As Jonathan states, a commit may contain more than one event and this gets all commits that contains at least one of the events I'm looking for. To filter further, you will have to look at each event in the commits.

雨落□心尘 2024-12-01 21:06:24

EventStore 本身并不特别关心提交的内容,这意味着它本身不会跟踪每次提交的单个事件类型。

这有几个原因。一是简单性,二是能够支持几乎任何存储引擎。我想让设计非常简单,模型也非常干净。此外,我希望避免对底层存储引擎要求过高,它可能或可能支持索引。如果您要查询特定类型,则您已经假设底层存储引擎提供索引。由于 EventStore 与存储引擎无关,因此两者不能混合。

另一件事是,“提交”实际上是一组一个或多个事件。当您加载提交时,您会获得所有事件。

一种可能的解决方案是加载某个时间点以来的所有内容,然后忽略您不关心的事件。另一种解决方案是让订阅者监听来自 EventStore 的所有消息,并通过事件类型的适当索引(异步/在另一个线程上)将消息推送到持久存储中。正确答案取决于您的性能要求。

The EventStore itself doesn't particularly care what is committed which means that, by itself, it doesn't track individual event types for each commit.

There are several reasons for this. One is simplicity and another is the ability to support virtually any storage engine. I wanted to keep the design extremely simple and the model very clean. Further I wanted to avoid being too demanding of the underlying storage engine which may or may not support indexing. If you're going to query on a specific type, you're already assuming that the underlying storage engine delivers indexing. Since the EventStore is storage engine agnostic, the two don't mix.

The other thing is that a "commit" is actually a set of one or more events. When you load a commit, you get all events.

One possible solution is just to load everything since a point in time and then ignore the events that you don't care about. Another solution is to have a subscriber that listens to all messages coming out of the EventStore that (asynchronously/on another thread) pushes the messages into persistent storage by with the appropriate indexing on event type. The correct answer depends upon your performance requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文