0
votes

I'm trying to use UseRetry with interval setting using MassTransit and Azure Service Bus as transport. Consumer code:

    public async Task Consume(ConsumeContext<ISimpleRequest> context)
    {
        _log.InfoFormat("Strated working on {0}", context.Message.CustomerId);
        throw new InvalidOperationException("some error");       
    }

Request service:

var _busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
        {
            var host =  cfg.Host("...", h =>
            {
            });
            cfg.MaxConcurrentCalls = 10;
            cfg.ReceiveEndpoint(host, "requestconsumerbag",
                e => { e.UseRetry(Retry.Interval(2,TimeSpan.FromMinutes(5))); e.Consumer<RequestConsumer>(); });
            cfg.UseServiceBusMessageScheduler();
        });
         _busControl.Start();

After message sending I expect to get one message immediately, one more after 5 minutes, and one more after 10 minutes. But I got one message immediately, two messages after 5 minutes, three messages after 10 minutes, and three messages every 5 minutes further. If this is bug how I can write code to force it work like I say before?

1

1 Answers

1
votes

The issue with long retry periods is that you're exceeding the lock timeout of Azure Service Bus. You should be using message redelivery instead of retry.

UseRetry() - is an inline retry filter. It retries the same message within the same delivery from the broker. It is meant to handle transient failures such as a SQL timeout or a deadlock issue. It is not meant for long-term retry operations.

It is a bit tricky to configure right now, and with 3.4.1 I'm not sure if the retry counts are integrated (they may not be), but for each message type you can use scheduled relivery.

x.Consumer<MyConsumer>(cfg =>
{
    cfg.ConfigureMessage<MyMessage>(x => x.UseScheduledRedelivery(r => r.Intervals(1000, 2000))
});

This will use the message scheduler (in Azure, it will schedule the message using EnqueueMessageTimeUtc).

This is cleaner in 3.5, which is yet to be released.