CQRS 模式问题

CQRS pattern questions

我正在学习 CQRS 模式,因为我们将在我们的新项目中使用它。到目前为止我的问题很少:

示例任务:我将使用 cron 命令从不同的提供者(不同的 API's)获取信息,这个 cron 命令的职责是:

  1. 从所有提供的数据中获取数据;
  2. 进行额外的 API 调用以获取图像和视频;
  3. 处理这些视频和图像(存储到 aws s3)并在数据库中上传 table;
  4. 从数据库中获取现有数据;
  5. 将新的 API 数据转换为系统实体,更新现有实体并删除不存在的实体;
  6. 坚持数据库。 ;

CQRS相关问题:

  1. 我可以在一个系统请求中包含几个 CQRS 命令和查询吗?在上面的示例中,我需要从数据库(查询)获取现有数据,持久化数据(命令)等等。
  2. 从 API 中获取数据的逻辑如何?我可以将其视为 CQRS 查询,因为它获取数据的过程或 CQRS 查询是从内部存储获取数据的唯一过程,而不是从外部 API?
  3. 将视频存储到s3和将信息存储到上传的过程如何table,我可以将资产存储到S3的过程视为CQRS命令并且该命令将return数据我需要存储以后上传?我不想立即存储它,因为上传实体是聚合的一部分,用于存储主要信息,其中主要信息实体是主要聚合实体。我知道命令不应该 return 任何东西或实体 ID 但在这里它会 return 所有关于商店资产的数据

如果上面的问题都是真的,那么我可以:

  1. 查询以获取 API 数据
  2. 查询以获取现有数据
  3. 要处理的命令 images/videos
  4. 命令 insert/update/delete 数据

不要对我进行严格的评判,我正在学习 DDD 的概念和相关模式。我只是问我不清楚的问题。非常感谢

Can I have few CQRS commands and queries inside of one system request? In the example above I need to get existing data from DB (query), persist data (command) and so on.

不,你不能。每个请求要么是一个命令,要么是一个查询。

what about the logic of fetching data from API's can I consider it as a CQRS query as its process of getting data or CQRS query it's the only process of getting data from internal storage, not from external API?

命令和查询引用本地数据库。通过远程从外部服务获取数据 API 是与另一个 BC 的集成(参见 DDD 上下文映射模式)。

What about the process of storing videos to s3 and storing information to uploads table, can I consider the process of storing assets to S3 as a CQRS command and this command will return data I need to store later to uploads?

将视频存储到 s3 不是命令,而是与外部服务的集成。您将必须集成(再次上下文映射模式)。

I do not want to store it immediately as upload entity is a part of aggregate to store main info where main info entity is the main aggregate entity.

我不知道您的域模型,但如果上传是聚合中的子实体,那么将内容存储在您的上传中 table 也不是命令。命令指的是聚合。在上传中存储信息 table 将是命令的一部分。

作为结论:

命令或查询是应用层边界(应用服务)的事务性操作。他们处理来自您的数据库的数据。每个command/query是一笔交易。