为什么我在回调中看不到我的响应数据?

Why can't i see my response data in my callback?

我们正在评估我公司的 nservicebus 以重写我们的销售流程。我们将使用 sagas 和 web api。我们 运行 进入一个块处理客户端的响应。我们使用 Handling Responses on the Client Side 作为指导。

从我们的客户端控制器,我们有这个代码:

    [Route("CreateProduct")]
    public ActionResult CreateProduct()
    {
        ProductCreatedResponse message = null;
        var product = new TestProduct { Id = ObjectId.GenerateNewId().ToString() };
        var command = new StartProductCommand { ProductId = product.Id, ProductName = "Product1" };

        var sync = ServiceBus.Bus.Send("Io.Server." + command.ProductName, command)
            .Register(ar =>
            {
                var localResult = (CompletionResult)ar.AsyncState;
                message = (ProductCreatedResponse)localResult.Messages[0];

                ViewBag.ResponseText = message.Status;
            }, null);

        sync.AsyncWaitHandle.WaitOne();

        return View("Index");
    }

从我们的 saga 处理程序中我们得到了这段代码:

    public void Handle(StartProductCommand message)
    {
        Data.ProductId = message.ProductId;
        Data.Status = "Product Created";

        var productCreatedResponse = new ProductCreatedResponse { Status = Data.Status };

        _bus.Reply(productCreatedResponse );
    }

localResult.Messages 为空。我做错了什么?

回调只能处理整数或枚举:http://docs.particular.net/nservicebus/messaging/handling-responses-on-the-client-side

再看看上面页面上的警告:

"If the server process returns multiple responses, NServiceBus cannot know which response message will be the last. To prevent memory leaks, the callback is invoked only for the first response. Callbacks won't survive a process restart (common scenarios are a crash or an IIS recycle) as they are held in memory, so they are less suitable for server-side development where fault-tolerance is required. In those cases, sagas are preferred."

在您的传奇中,您应该删除我怀疑被注入的 _bus private 属性。你应该从 Saga< T > abstract class 继承你的 saga。此 class 包含为您注入的总线 public 属性。要报告部分 saga 进度,您应该使用 Bus.ReplyToOriginator 方法而不是 _bus.Reply.

所有这些都在 docs, you might need to look in this section 中有完整描述。

我找到了答案。愚蠢的问题。 nservicebus 的 nuget 包不同步。哇!!! nservicebus 是分布在多个项目中的少数资源之一。我的网络主机上有 v5.12,然后我通过 nuget 添加了一个端点,那个版本是 v5.2。他们一定改变了版本之间的序列化。这太容易了。他们应该在主机控制台中发出警告,告诉您您的版本不同步并且需要更新。