我们是否需要在 CQRS 中混合使用同步和异步命令处理程序?

发布于 2024-09-18 22:54:16 字数 270 浏览 0 评论 0原文

  1. 用户在我们的网站上注册并登录。RegisterUserCommand 被发送到异步命令处理程序。
  2. 用户想要更改其地址,但 RegisterUserCommand 尚未处理。系统中没有用户记录。

这是同步命令处理程序的情况吗?在对用户进行身份验证之前将创建用户记录。或者我应该重新考虑注册后对真实用户的要求?在创建帐户之前,用户将无法访问该网站。如果用户不能立即访问系统,则使用率可能会下降。

在 CQRS 系统中混合使用同步和异步命令处理程序是否很常见?

  1. A user registers on our site and gets logged in. A RegisterUserCommand is sent to an asynchronous command handler.
  2. The user wants to change their address but the RegisterUserCommand has not been processed yet. There is no user record in the system.

Is this a case for synchronous command handlers? A user record would be created prior to authenticating the user. Or should I rethink the requirement to authentic users after registration? Users won’t be able to gain access to the site until their account has been created. If users don’t gain access to the system straightaway there may be drop off in usage.

Is it common to see a mix of synchronous and asynchronous command handlers in a CQRS system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-09-25 22:54:16

一切都在异步运行。为了简单起见,队列是先进先出的;另外,每个分区有一个处理线程。这样命令总是按照发送的顺序进行处理。另外,我们仍然具有可扩展性,因为每个分区的线程可以简单地转换为每个分区的机器,而不需要重新分区整个解决方案。

在某些情况下,我们可能需要同步处理(在我的例子中,示例是初始用户注册,因为我们需要在让他继续之前验证服务器上的一些内容)。在这种情况下,发送命令后,用户会看到“请等待几秒钟,您的注册正在处理中”。一旦注册被确认(或失败),用户就会自动进入下一个屏幕。这对于 Web UI 中的 AJAX 来说是微不足道的。桌面用户界面甚至更简单。

I have everything running in async. To keep everything simple, queues are FIFO; plus there is one processing thread per partition. This way commands are always processed in the order of sending. Plus we still have the scalability, since thread per partition could be simply turned into machine per partition without the need to repartition the entire solution.

There are a few cases, where we might want synchronous processing (in my case example would be initial user registration, since we need to validate a few things on the server before letting him to go on). In this case after the command is send, user is shown the "please wait for a few seconds, while your registration is processed". As soon as the registration is confirmed (or failed), user is automatically taken to the next screen. This is trivial to do with AJAX in web UI. Desktop UIs are even simpler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文