Search code examples
.net-corerabbitmqmasstransit

MassTransit.PayloadNotFoundException


when i try to consume a message, i get this error in rabbitmq management:

MT-Fault-ExceptionType: MassTransit.PayloadNotFoundException
MT-Fault-Message:   The payload was not found: MassTransit.MessageSchedulerContext
MT-Fault-StackTrace:    at MassTransit.PipeExtensions.GetPayload[TPayload](PipeContext context) in /_/src/MassTransit.Abstractions/Middleware/PipeExtensions.cs:line 55
at MassTransit.Context.ScheduleMessageRedeliveryContext`1.ScheduleRedelivery(TimeSpan delay, Action`2 callback) in /_/src/MassTransit/Contexts/Context/ScheduleMessageRedeliveryContext.cs:line 28
at MassTransit.Middleware.RedeliveryRetryFilter`2.Send(TContext context, IPipe`1 next) in /_/src/MassTransit/Middleware/RedeliveryRetryFilter.cs:line 101

and here is the configuration:

private static void AddMessagingConfiguration(IServiceCollection services, WebApplicationBuilder builder)
    {
        services.AddMassTransit(busConfigurator =>
        {
            busConfigurator.AddConsumer<GtsDocumentConsumer>();
            busConfigurator.AddEntityFrameworkOutbox<CompanyGoodsDbContext>(outboxConfigurator =>
            {
                outboxConfigurator.UseSqlServer();
                outboxConfigurator.UseBusOutbox();
                outboxConfigurator.QueryMessageLimit = 10;
                outboxConfigurator.QueryDelay = TimeSpan.FromSeconds(1);
                outboxConfigurator.QueryTimeout = TimeSpan.FromSeconds(30);
            });

            busConfigurator.AddOptions<MassTransitHostOptions>()
                .Configure(options =>
                {
                    options.WaitUntilStarted = true;
                    //options.StartTimeout = TimeSpan.FromSeconds(1);
                    //options.StopTimeout = TimeSpan.FromSeconds(30);
                });
            

            busConfigurator.UsingRabbitMq((busContext, transportConfigurator) =>
            {
                transportConfigurator.Host(builder.Configuration["EventBusSettings:HostAddress"], "/", hostConfiguration =>
                {
                    hostConfiguration.Username(builder.Configuration["EventBusSettings:Username"]);
                    hostConfiguration.Password(builder.Configuration["EventBusSettings:Password"]);
                });

                transportConfigurator.AutoStart = true;
                transportConfigurator.UseMessageRetry(r => r.Immediate(5));
                transportConfigurator.UseScheduledRedelivery(r =>
                    r.Intervals(TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(15), TimeSpan.FromMinutes(30)));
                transportConfigurator.ConfigureEndpoints(busContext);
            });
        });
    }

this configuration works fine when we are testing everything locally in docker between two applications but now when both applications runs on the server I got this error


Solution

  • UseScheduledRedelivery -> UseDelayedRedelivery

    Requires the delayed-exchnage plug-in on RabbitMQ.

    Also, order matters, as per the documentation:

    UseDelayedRedelivery then UseMessageRetry