c# - 处理排队的命令处理程序响应。 CQRS

标签 c# domain-driven-design messaging cqrs masstransit

考虑情况:

public class OrderController {
    IBus bus;

    public OrderController(IBus bus) {
        this.bus = bus;
    }

    public ActionResult Checkout(String orderId) {
        var command = new CheckoutOrderCommand(orderId);
        bus.Send(command);

        return Redirect("on-success-url");
    }
}

相应的命令处理程序(在单独的程序集中定义)正在等待处理传入消息。

但是我们已经说过发送一切正常 return Redirect("on-success-url");

  1. 如果处理程序无法保存对域的更改怎么办?

    好吧,可以在命令处理程序端使用队列来发布响应,将 Web 应用程序订阅到队列。

  2. 最终用户如何获得即时/同步的 UI 响应,以反射(reflect)对域所做的真实更改?我应该这样做吗?

  3. 通过消息总线处理传入命令是否只适用于后台任务而不需要确认?

最佳答案

这取自«Busting some CQRS myths», Jimmy Bogard blog您可能感兴趣:

Myth #4 – Commands are fire-and-forget

How many business processes in your line of work are truly fire and forget? You typically need at least a synchronous acknowledgement that the command was received and accepted. If you’re doing an async send of the command, how do you notify the user? Email? Are they OK with this?

Instead, with commands that need heavy lifting to fulfill the request, we really have two things going on:

  • Accepting the request
  • Fulfilling the request

Accepting the request should be synchronous. Fulfilling need not be. But for the model of an asynchronous fulfillment, we still will likely need ways of correlating requests etc., and this is where you often see workflows/processes/sagas come into play.

我总是尝试让我的命令同步。如果流程时间很长,我会使用流程管理器或 saga 之类的东西。

关于c# - 处理排队的命令处理程序响应。 CQRS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29027074/

相关文章:

c# - 如果在单独的方法中调用,为什么 Parallel.Invoke 会快得多?

domain-driven-design - DDD 如何获取值对象列表

c# - 如何使用 Visual Studio 2015 运行 UWP NUnit 测试?

c# - 检测密码保护的word文件

c# - 没有参数的 CQRS 查询处理程序

database - 如何避免首先以 DDD 友好的方式检索聚合根以进行优化?

java - qpid如何配置接收器

MySQL获取2个人之间的最新消息

Android,我书中的快速问题

c# - 设置 WPF 用户控件的样式