MassTransit: The connection between the server and the consumer is not re-established after network problems
Hello all!
I have very large problem with MassTransit. For reproduction purposes I have created a simple service, the code for which is as follows:
` public class Worker : BackgroundService { private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
sbc.Host(new Uri("rabbitmq://localhost:6666/"), h =>
{
h.Username("guest");
h.Password("guest");
});
sbc.ReceiveEndpoint("test_queue",
ep =>
{
ep.Handler<Message>(context =>
{
return Console.Out.WriteLineAsync($"Received: {context.Message.Text}");
});
});
});
await bus.StartAsync(); // This is important!
await Task.Factory.StartNew(async () =>
{
while (true)
{
try
{
var message = new Message();
await bus.Publish(message);
await Task.Delay(1000);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
});
Console.WriteLine("Press any key to exit");
await Task.Run(() => Console.ReadKey());
await bus.StopAsync();
}
} public class Message { private static int counter = 0; public string Text { get { counter++;
if (counter % 20 == 0)
{
throw new Exception();
}
return DateTimeOffset.UtcNow.ToString() + ":" + counter.ToString();
}
}
}`
I also made two simple scripts that delete and resume the connection using ncat.
Setting up the connection:
:loop ncat -l 6666 -k -e "ncat 127.0.0.1 5672" timeout 20 goto loop
Killing the connection:
:loop taskkill /F /IM ncat.exe timeout 60 goto loop
After several cycles of such resuming and breaking the connection, the consumer is no longer seen in the RabbitMQ Management UI. The connection between the server and the consumer is not re-established. My question is as follows. Has anyone ever encountered such an error and knows how to resolve it?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (10 by maintainers)
Commits related to this issue
- Added "Unexpected Exception" as an additional exception that can be retried. Related to #3209 — committed to phatboyg/MassTransit by phatboyg 2 years ago
Thank you for all your time. MassTransit rules 😃
https://docs.google.com/document/d/130PcFTIKQQdJGGDpFbA6-CK9OqkTOmMuaQzwzWO9Id4/edit?usp=sharing
TL/DR: Q1/2022, aka, within the next three weeks.