在CQRS中如何与NServiceBus一起更新命令和查询存储 [英] In CQRS how to work with NServiceBus to update Command and Query store
问题描述
在CQRS中,如何确定命令处理程序正在以事务方式更新写存储和读存储?
In CQRS, how do you make sure a command handler is updating the write store and read store transactionally?
我不确定这两个步骤是否应作为交易? 还是在这里依靠最终的一致性?意味着读取存储将最终被更新?
I am not sure if these two steps are suppoed to be a transaction? Or do you rely on eventual consistency here? Meaning the read store will be updated eventually?
使用NServiceBus 5或6进行此操作的(或一种)常见方法是什么?
在我们的应用程序中,我们在命令端具有IRepository<T>
(添加,更新)来更新Sql Server数据库.
查询方面很简单.实体框架DbContext
之上的数据库和外观.
In our application, we have IRepository<T>
(Add, Update) for the command side to update Sql Server database.
The query side is simple. A database and a facade on top of Entity Framework DbContext
.
命令端的步骤将是:
- MVC控制器从View接收数据
- 控制器操作创建一个Command/Message对象,并将其发送到总线.
- 适当的命令处理程序会创建适当的域对象并对其进行验证.
- 如果有效,请使用IRepository插入或更新数据库.
- 现在呢?
这是否一定是NServiceBus中的传奇,步骤1和步骤2更新了命令存储区和读取存储区?
Does this have to be a Saga in NServiceBus, where Step 1 and 2 update the command store and read store?
谢谢.
推荐答案
我看到的流程如下:
- 控制器接收动作并在命令总线中发出命令
- 触发适当的命令处理程序并更新写模型
- 在命令处理程序中,会触发一个事件
- 触发适当的事件处理程序,并更新读取的模型
因此,在事件处理程序中完成读取模型的更新-因此最终的一致性
So updating the read models get done in an event handler - hence the eventual consistency
希望这会有所帮助!祝你好运!
Hope this helps! Best of luck!
这篇关于在CQRS中如何与NServiceBus一起更新命令和查询存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!