Skip to content

Scheduled Delivery

INFO

This functionality as introduced in Wolverine 1.6.0

WolverineFx.AzureServiceBus now supports native Azure Service Bus scheduled delivery. There's absolutely nothing you need to do explicitly to enable this functionality.

So for message types that are routed to Azure Service Bus queues or topics, you can use this functionality:

cs
public async Task SendScheduledMessage(IMessageContext bus, Guid invoiceId)
{
    var message = new ValidateInvoiceIsNotLate
    {
        InvoiceId = invoiceId
    };

    // Schedule the message to be processed in a certain amount
    // of time
    await bus.ScheduleAsync(message, 30.Days());

    // Schedule the message to be processed at a certain time
    await bus.ScheduleAsync(message, DateTimeOffset.Now.AddDays(30));
}

snippet source | anchor

And also use Azure Service Bus scheduled delivery for scheduled retries (assuming that the listening endpoint was an inline Azure Service Bus listener):

cs
using var host = Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.Policies.OnException<TimeoutException>()
            // Just retry the message again on the
            // first failure
            .RetryOnce()

            // On the 2nd failure, put the message back into the
            // incoming queue to be retried later
            .Then.Requeue()

            // On the 3rd failure, retry the message again after a configurable
            // cool-off period. This schedules the message
            .Then.ScheduleRetry(15.Seconds())

            // On the next failure, move the message to the dead letter queue
            .Then.MoveToErrorQueue();

    }).StartAsync();

snippet source | anchor

Released under the MIT License.