How to defer an event in NServiceBus 6.0?

94 views
Skip to first unread message

narendra chava

unread,
Sep 20, 2017, 3:03:46 PM9/20/17
to Particular Software
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.

Daniel Marbach

unread,
Sep 20, 2017, 3:16:45 PM9/20/17
to Particular Software
Hi,

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);


Hope that helps
Daniel

narendra chava

unread,
Sep 20, 2017, 3:27:13 PM9/20/17
to Particular Software
Thank you Daniel, that worked like a charm !! I'm a little concerned that we're not following the best practices, but sometimes developers might not have that privilege.
Reply all
Reply to author
Forward
0 new messages