0

I'm using MassTransit version 8.3.6 with Azure Service Bus, and I'm trying to utilize the delayed re-delivery feature in MassTransit. However, as soon as I enqueue the message, I encounter the following error in my logs:

MassTransit.MessageTimeToLiveExpiredException: sb://providerappapiv2.servicebus.windows.net/note => The message expired: ac5a0000da2bb05c4b6f08dd5518d768

When I remove this line from the configuration:
e.UseDelayedRedelivery(r => r.Intervals(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30)));
everything works as expected.

What am I doing wrong?

Here's my configuration code:

services.AddMassTransit(x =>
{
    x.SetKebabCaseEndpointNameFormatter();

    x.AddConsumer<NoteConsumer>();

    x.UsingAzureServiceBus((context, cfg) =>
    {
        cfg.Host(config.GetConnectionString("AzureServiceBus"));

        cfg.UseServiceBusMessageScheduler();

        cfg.ReceiveEndpoint("note", e =>
        {
            e.DefaultMessageTimeToLive = TimeSpan.FromDays(14);
            e.EnableDeadLetteringOnMessageExpiration = true;
            e.MaxDeliveryCount = 15;
            e.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(10);
            e.MaxSizeInMegabytes = 5120;
            e.RequiresDuplicateDetection = true;

            e.UseDelayedRedelivery(r => r.Intervals(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30)));
            e.UseMessageRetry(r => r.Intervals(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(8)));

            if (e is IServiceBusReceiveEndpointConfigurator sb)
            {
                sb.ConfigureDeadLetterQueueDeadLetterTransport();
                sb.ConfigureDeadLetterQueueErrorTransport();
            }

            e.ConfigureConsumer<NoteConsumer>(context);
        });

        cfg.ConfigureEndpoints(context);
    });

    x.AddMediator(cfg =>
    {
        //...
    });
});

Any insights into what might be going wrong would be appreciated.

EDIT: The TTL exception issue occurs only when the queue is not created before starting the application. If the queue already exists, the message is delivered with a retry; however, delayed re-delivery still does not work.

8
  • Try Host Options waitUntilStarted. See masstransit.io/documentation/configuration Commented Feb 24 at 22:26
  • I tried that, still getting same results Commented Feb 25 at 2:20
  • configuration to force MassTransit to set the correct TTL when auto-creating the queue: e.SetQueueAttributes(new CreateQueueOptions("note") { DefaultMessageTimeToLive = TimeSpan.FromDays(14), LockDuration = TimeSpan.FromMinutes(5), MaxDeliveryCount = 15, EnableDeadLetteringOnMessageExpiration = true }); Commented Feb 25 at 9:29
  • Use e.UseScheduledRedelivery(r => r.Intervals(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30))); Commented Feb 25 at 9:30
  • consider enabling the outbox pattern: e.UseInMemoryOutbox(); Commented Feb 25 at 9:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.