如何延迟 NServiceBus 6.0 中的事件?

How to defer an event in NServiceBus 6.0?

我们使用 NserviceBus 作为我们的消息传递基础设施,使用 RabbitMQ 作为传输。 我正在尝试从 5.* 版本升级到 NServiceBus 6.0。在 5.0 中,我们可以使用 "Bus.Defer()" 延迟事件。但似乎在 6.0 中我们只能延迟消息而不能延迟事件??

如果我使用下面的代码,消息是 "event",我会收到一条错误消息,指出应该发布事件。

        var sendOptions = new SendOptions();
        sendOptions.DoNotDeliverBefore(DateTimeOffset.Now.AddMinutes(30));
        sendOptions.RouteToThisEndpoint();
        return context.Send(message, sendOptions);

context.Publish(message, new PublishOptions()) 方法接受 "PublishOptions" 没有延迟选项。

我是不是漏掉了什么?如果有人可以提供帮助,我们将不胜感激。

Some changes are not immediately effective, so we will have to defer some of those events.

发布者不应受任何订阅者的约束。

假设产品创作系统发布 ProductDataUpdate 事件而不管实际生效日期何时发生是否正确?在这种情况下,您已经收到有关 做出的决定的通知。作为订户,你打算用它做什么是另一回事,而且完全是内部的。

您可以发送一条命令,为了本次讨论,将其称为 UpdateProductCost,如果 EffectiveDate 是未来的消息,那将是一条延迟消息。否则,这是一个即时命令。

我在另一个论坛上得到了一个答案,我认为这是最相关的,所以将其张贴在这里,以便将来对某人有所帮助。感谢丹尼尔·马尔巴赫

https://groups.google.com/forum/#!topic/particularsoftware/ivy1wdsycT8

v5 中的

Bus.Defer 在内部始终执行发送操作。与 v6 的不同之处似乎在于它自动禁用了消息传递最佳实践。您可以通过调用

来实现相同的目的
        var sendOptions = new SendOptions();
        sendOptions.DoNotDeliverBefore(DateTimeOffset.Now.AddMinutes(30));
        sendOptions.RouteToThisEndpoint();
        sendOptions.DoNotEnforceBestPractices();
        return context.Send(message, sendOptions);

https://docs.particular.net/nservicebus/messaging/best-practice-enforcement