1

We're using NserviceBus as our messaging infrastructure with RabbitMQ as the transport. I'm trying to upgrade to NServiceBus 6.0 from 5.* version. In 5.0, we could defer events using "Bus.Defer()". But it seems like in 6.0 we can defer only messages but not events ??

If I use below code with message being an "event", I get an error saying that events should be published.

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

but context.Publish(message, new PublishOptions()) method takes in "PublishOptions" which does not have an option to defer.

Am I missing something here ? Appreciate if someone could help.

Naren
  • 298
  • 2
  • 10
  • An event is based on something that has already taken place, not an action that you need to defer. If you need to delay an action, then perhaps it should be a command? Without a broader scope of the problem, hard to tell. Can you add some details of what you're doing from the process point of view? – Sean Feldman Sep 20 '17 at 19:03
  • There is a Product Authoring system which publishes events when the product data is changed. we're a subscriber and we will have to update our system when the product data changes. Some changes are not immediately effective, so we will have to defer some of those events. For example, an event might look like this. 9/22/2017 The fact that the product update is an event or message or command is always debatable, but I cannot change it to a message or command because that is causing other issues. – Naren Sep 20 '17 at 19:14

2 Answers2

1

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

The publisher should not be constrained by any of the subscribers.

Is it correct to assume that Product Authoring system publishes ProductDataUpdate events regardless of when the actual effective date will take place? In such case, you are already notified about a decision that was made. What are you, as a subscriber, going to do with it is a different thing and entirely internal.

You could send a command, for the sake of this discussion call it UpdateProductCost, that would be a delayed message if EffectiveDate is in the future. Otherwise, it's an immediate command.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • I agree with you, Sean, you're absolutely right. I might actually do that when time permits so that I follow the best practices enforced by NserviceBus. But right now, I'm looking for a quick alternative. Thanks for your suggestions. – Naren Sep 20 '17 at 19:39
1

I've got an answer in another forum and I think it is the most relevant, So posting it here so that it could help someone in future. Thanks to Daniel Marbach

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

Bus.Defer in v5 was internally always doing a send operation. It seems the difference to v6 is that it automatically disabled the messaging best practices. You can achieve the same by calling

        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

Naren
  • 298
  • 2
  • 10