简体   繁体   中英

CQRS and slow commands on legacy system

I am new at CQRS and want advice how to implement this over an legacy system.

I have some questions:

  1. The database will remain in the legacy system. I'm guessing right that we do not have any use for Event Sourcing?

  2. Some commands will take time to perform (anywhere from a few seconds to a few minutes). How do we handle it with CQRS?

I am looking to solve this as follows:

  1. Client sends UpdateSomeDataCommand
  2. UpdateSomeDataHandler creates a new thread that retrieve the data from the legacy system
  3. The client use the read model to get cached data and present it to the user
  4. When the UpdateSomeDataHandler is ready to retrieve data, it sends the SomeDataUpdated event
  5. The read model react to SomeDataUpdated and store the new data in its cache database
  6. The read model use INotifyPropertyChanged to notify the client that updated data is available.
  7. The client retrieves the update data from the read model and present it to the user.

It feels a like I'm doing it wrong. But I can not think of anything better.

  1. We cannot tell you if you need Event-Sourcing. There are bazillion techniques achieving what Event-Sourcing does. It's just a "database" where all commands are stored which change anything in your database. You can use it for analysis or debugging or rewind-play scenarios (again for business purposes, for analysis or debugging). So it depends on what you want to do. You don't need Event-Sourcing for the sake of having Event-Sourcing.

  2. Just ask yourself what you want to achieve. Your path looks good. But we don't know if it is appropriate. Step 1, 2, 4 and 5 are somewhat mandatory. 3, 6 and 7 looks to me like you are making judgements on what to do with the information in between. This completely relies upon the business model you are processing. If this is mandatory - then that is a good way.

To make it sound a little clearer. You are just dispatching commands to a specific service that takes care of a command-database. So far so good. Does the read-database (the front-end user) have to know that a heavy command is issued on an entity? Does the frontend need to be informed when new data is available in the read-database - so that it can automatically load the new data in the frontend?

If so - your approach is good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM