Does the CQRS project need a messaging infrastructure such as NServiceBus?
The short answer is no.
This is the first time I hear about the “model reading model” mentioned by eulerfx. This is a pretty nice name, but there is something else:
The basic idea behind the query part is to request a denormalized view of your data. In the "read-model" link, you will notice that the query used to populate the read model does some lifting. In the given example, the required data manipulations are not so complicated, but what if they become more complex? This is where denomination begins. When you execute your “command” part, the next step is to denormalize the data and save the results for readability. All hard work must be done by your domain.
That is why you are asking about messaging. There are several methods here:
- denormalized data in the same database, the same table, different columns
- denormalized data in one database in another table
- denormalized data in another database
This is the repository. How about consistency?
- immediately matches
- finally consistent
The simplest solution (quick win) is to denormalize your data in your domain, and then, after saving the objects of your domain through the repository, you immediately save the denomalized data in the same data store, the same table (s), different columns. At 100%, and you can immediately start reading denormalized data.
If you really want to, you can create a separate group of objects to transport this data, but it's easier to just write a simple query layer that returns some data transfer object provided by your data access structure (in the case of .Net, it should be DataRow / DataTable ). There is absolutely no reason for imagination. There will always be exceptions, but then you can go ahead and write a data container.
For possible consistency, you will need some form of queue and related processing. You can turn your own decision or you can choose a service bus. It is up to you and your time / technical limitations :)
By the way, I have a free open source service bus here:
Any feedback would be welcome. But any old service bus (MassTransit / NServiceBus / etc.) will do.
Hope this helps.