UseInMemoryOutbox doesn't work as expected in case of combining Retry and DelayedRedelivery policies
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with the lastest version?
Yes
Environment
- Operating system: Windows 10 Pro
- Visual Studio version: 2017
- Dotnet version: Net Core 2.0
Steps to Reproduce
(Write your steps here:)
- Configure UseDelayedRedelivery and UseMessageRetry
- 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Wow! Just noticed that 5.0.1 been released! So fast, guys!
And configuration below now works as expected
thanks much!
Great! Looking forward 5.0.1!