question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UseInMemoryOutbox doesn't work as expected in case of combining Retry and DelayedRedelivery policies

See original GitHub issue

Is this a bug report?

Yes

Can you also reproduce the problem with the lastest version?

Yes

Environment

  1. Operating system: Windows 10 Pro
  2. Visual Studio version: 2017
  3. Dotnet version: Net Core 2.0

Steps to Reproduce

(Write your steps here:)

  1. Configure UseDelayedRedelivery and UseMessageRetry
  2. Add UseInMemoryOutbox

Expected Behavior

Messages published before the consumer has failed should not be issued.

Actual Behavior

In the example below I don’t expect message InnerCommand to be consumed at all, but in reality I get consumer hit twice

using GreenPipes;
using MassTransit;
using MassTransit.RabbitMqTransport;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System;
using System.Threading.Tasks;

namespace Receiver
{
    class Program
    {
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                    .AddJsonFile("appsettings.json", true, true);

            var configuration = builder.Build();

            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Console()
                .ReadFrom.Configuration(configuration)
                .CreateLogger();

            Log.Information("Starting Receiver...");

            var services = new ServiceCollection();

            services.AddSingleton(context => Bus.Factory.CreateUsingRabbitMq(x =>
            {
                IRabbitMqHost host = x.Host(new Uri("rabbitmq://guest:guest@localhost:5672/test"), h => { });

                x.UseDelayedExchangeMessageScheduler();

                //x.UseInMemoryOutbox();

                x.ReceiveEndpoint(host, $"receiver_queue", e =>
                {
                    x.UseInMemoryOutbox();

                    e.Consumer<TestHandler>();

                    e.UseDelayedRedelivery(r =>
                    {
                        r.Interval(1, TimeSpan.FromMilliseconds(100));
                        r.Handle<Exception>();
                    });

                    e.UseMessageRetry(r =>
                    {
                        r.Interval(1, TimeSpan.FromMilliseconds(100));
                        r.Handle<Exception>();
                    });
                });

                x.UseSerilog();
            }));

            var container = services.BuildServiceProvider();

            var busControl = container.GetRequiredService<IBusControl>();

            busControl.Start();

            busControl.Publish<TestCommand>(new
            {
                Id = NewId.NextGuid()
            });

            Log.Information("Receiver started...");
        }
    }

    public interface TestCommand
    {
        Guid Id { get; }
    }

    public interface InnerCommand
    {
        Guid Id { get; }
    }

    public class TestHandler : IConsumer<TestCommand>, IConsumer<InnerCommand>
    {
        static int count = 0;

        public Task Consume(ConsumeContext<TestCommand> context)
        {
            context.Publish<InnerCommand>(new
            {
                Id = context.Message.Id
            });

            var redeliveryCount = context.Headers.Get<string>("MT-Redelivery-Count");

            Log.Information($"MT-Redelivery-Count: {redeliveryCount}; Total: {++count}");

            throw new Exception("something went wrong...");
        }

        public Task Consume(ConsumeContext<InnerCommand> context)
        {
            Log.Information($"Inner command: {context.Message.Id}");

            return Task.CompletedTask;
        }
    }
}

Have I missed something and it should be configured some other way?

Reproducible Demo

https://github.com/pshenichnov/TestInMemoryOutbox

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pshenichnovcommented, Apr 24, 2018

Wow! Just noticed that 5.0.1 been released! So fast, guys!

And configuration below now works as expected

                x.ReceiveEndpoint(host, $"receiver_queue", e =>
                {
                    e.UseDelayedRedelivery(r => r.Interval(1, TimeSpan.FromMilliseconds(100)));
                    e.UseMessageRetry(r => r.Interval(1, TimeSpan.FromMilliseconds(100)));
                    e.UseInMemoryOutbox();

                    e.Consumer<TestHandler>();
                });

thanks much!

0reactions
pshenichnovcommented, Apr 24, 2018

Great! Looking forward 5.0.1!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combining retries and redelivery
in this case I get message redelivered two times using second-level retry. ... to have the delayed redelivery first, followed by the immediate...
Read more >
Exceptions
The UseMessageRetry method is an extension method that configures a middleware filter, in this case the RetryFilter . There are a variety of...
Read more >
ScheduledRedelivery combined Retry not redelivering to ...
MessageRetry is working as expected. I was also expecting the messages would be redelivered to the queue again after each interval specified ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found