In CQRS how to work with NServiceBus to update Command and Query store

若如初见. 提交于 2019-12-11 10:46:23

问题


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?

What is the (or a) common way to do this using NServiceBus 5 or 6?

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.

The steps on the command side would be:

  1. MVC controller receives data from View
  2. controller action creates a Command/Message object and sends it to the bus.
  3. The proper command handler creates the appropriate domain object and does validation on it.
  4. If valid, uses IRepository to insert or update the database.
  5. Now what?

Does this have to be a Saga in NServiceBus, where Step 1 and 2 update the command store and read store?

Thank you.


回答1:


The flow I see is the following:

  • the controller receives an action and emits a command in the command bus
  • the proper command handler gets fired and the write models get updated
  • in the command handler, an event is fired
  • the proper event handler gets fired and the read models get updated

So updating the read models get done in an event handler - hence the eventual consistency

Hope this helps! Best of luck!



来源:https://stackoverflow.com/questions/33133141/in-cqrs-how-to-work-with-nservicebus-to-update-command-and-query-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!