CQRS-如何处理新的报表表(或:如何从事件存储中导入所有历史记录) [英] CQRS - how to handle new report tables (or: how to import ALL history from the event store)

查看:85
本文介绍了CQRS-如何处理新的报表表(或:如何从事件存储中导入所有历史记录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了一些CQRS示例实现(Java / .Net),它们使用事件源作为事件存储,并使用简单的(No)SQL存储作为报告存储。

I've studied some CQRS sample implementations (Java / .Net) which use event sourcing as the event store and a simple (No)SQL stores as the 'report store'.

看起来不错,但是我似乎在所有示例实现中都缺少一些东西。

Looks all good, but I seem to be missing something in all sample implementations.

如何处理新的报表存储/屏幕应用程序已经投产了?以及如何将现有(最新)数据从事件存储导入新的报表存储?

How to handle the addition of new report stores / screens, after an application has gone in production? and how to import existing (latest) data from the event store to the new report store?

即:

想象一个基本的DDD / CQRS驱动的CRM应用程序。
每个屏幕(实际上是视图)都有其自己的结构化报表存储区(一个SQL表)。
所有这些视图都可以通过使用处理程序来监听域事件(CustomerCreated / CustomerHasMoved等)进行更新。

Imagine a basic DDD/CQRS driven CRM application. Every screen (view really) has it's own structured report store (a SQL table). All these views get updated using handlers listening to the domain events (CustomerCreated / CustomerHasMoved, etc).

CRM的一个功能是它可以登录电话通话(PhoneCallLogged事件)。由于时间限制,我们仅在CRM的V1中实现了电话记录(查看和报告谁处理了将在V2中实现的哪个电话)

One feature of the CRM is that it can log phone calls (PhoneCallLogged event). Due to time constraints we only implemented the logging of phone calls in V1 of the CRM (viewing and reporting of who handled which phone call will be implemented in V2)

在生产过程中,我们希望实现每个客户和销售代表的已记录电话的报告。

After a time running in production, we want to implement the 'reporting' of logged phone calls per customer and sales representative.

因此,我们需要添加一些屏幕(视图),支持报告表(在报告存储区中)并用事件存储区中已收集的数据填充它...

So we need to add some screens (views) and the supporting report tables (in the report store) and fill it with the data already collected in the Event Store...

那是我在查看样本时卡住的地方我学。他们不处理从事件存储到(新)报告存储的现有(历史)数据导入。

That is where I get stuck while looking at the samples I studied. They don't handle the import of existing (history) data from the event store to a (new) report store.

EventRepository(DomainRepository)的所有样本都只有一个方法'GetById'和'Add',它们不支持一次获取所有聚合根以填充新的报表。

All samples of the EventRepository (DomainRepository) only have a method 'GetById' and 'Add', they don't support getting ALL aggregate roots in once to fill a new report table.

如果没有此初始数据导入,则新屏幕仅针对新发生的事件进行更新。不适用于已经记录的电话(因为没有针对PhoneCallLogged事件的报告侦听器)

Without this initial data import, the new screens are only updated for newly occurred events. Not for the phone calls already logged (because there was no report listener for the PhoneCallLogged event)

任何建议,建议吗?

预先感谢

Remco

推荐答案

您在现有事件日志上重新运行该处理程序(例如,通过新事件处理程序播放旧事件)

You re-run the handler on the existing event log (eg you play the old events through the new event handler)

考虑一下您的示例……您有大量的PhoneCallLoggedEvents在您的事件日志中。拿起新的手柄,并通过它播放所有旧事件。这就好像它一直在运行,并且将继续处理到达的任何新事件。

Consider you example ... you have a ton of PhoneCallLoggedEvents in your event log. Take your new Handles and play all the old events through it. It is then like it has always been running and will just continue to process any new events that arrive.

欢呼声,

格雷格

这篇关于CQRS-如何处理新的报表表(或:如何从事件存储中导入所有历史记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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