gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:58:29 24 4
gpt4 key购买 nike

考虑情况:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com