当我们想要历史记录时,阅读事件源代码是否正确? [英] Is it right to read the event sourcing when we want history?

查看:99
本文介绍了当我们想要历史记录时,阅读事件源代码是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用CQRS架构。一切都是通过汇总执行的,因此每个用户的操作都保存为事件在我的事件源存储中。

My application use CQRS architecture. Everything is performed through my aggregates, thus each user's action is saved as an event in my event source store.

现在,我需要一个新的表格来显示每个用户的历史记录操作在我的应用程序中执行,该怎么办?

Now, I need a new form which shows the history of every action performed in my application, so what should I do ?

1-读取事件存储?

1 - Read the event store ? How ?

2-在每个域处理程序中发布一个事件,例如 SavedToHistory(User user,Action action,DateTime date),然后在事件处理程序中将其存储在我的读取数据模型?

2 - Publish an event in each of my domain handler like "SavedToHistory(User user, Action action, DateTime date) then in my event handlers, store it in my read data model ?

推荐答案

由于CQRS的整体思想是将读写与存储分开(读与再次写入相比),我认为您可以采取的最一致的操作是将非规范化的历史数据写入Read数据库并从其中读取,而不是尝试从Event Store中读取。

Since the whole idea of CQRS is to have separation of reading and writing, and of storage (reading vs writing again), I think the most consistent action you can take is to write denormalized history data to the Read database and read it from there rather than trying to read it from the Event Store.

这很简单;您可以编写一个通用的反规范化器,该规范化器可以将事件存储中的任何新事件写入到Read数据库中的反规范化版本,或者您可以具有专门的反规范化器-这取决于您想要的方式在应用程序中显示历史记录。

This can be straightforward; you can write a general denormalizer that can write any new event in the Event Store to a denormalized version in the Read database, or you can have specialized denormalizers -- it depends on how you want to display history in your application.

无论哪种方式,都将事件的非规范化版本写入Read DB,这样您的应用程序就无需确切知道事件的结构d在活动存储区中。

Either way, write denormalized versions of your events to the Read DB so that your application will not need to know exactly how events are structured in the Event Store.

这篇关于当我们想要历史记录时,阅读事件源代码是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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