Warm tip: This article is reproduced from serverfault.com, please click

Connect Failed: Broker unreachable

发布于 2018-03-15 00:55:08

After updating MassTransit packages to the latest version (4.1.0.1426-develop) I experience problems with registering more then 26 queues. For example, code below crushes with error

[20:51:06 ERR] RabbitMQ Connect Failed: Broker unreachable: guest@localhost:5672/test

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 => { });

        for (var i = 0; i < 27; i++)
        {
            x.ReceiveEndpoint(host, $"receiver_queue{i}", e =>
            {
                e.Consumer<TestHandler>();
            });
        }

        x.UseSerilog();
    }));

    var container = services.BuildServiceProvider();

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

    busControl.Start();

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

So, it can't register 27 queues. However it works if I decrease the number to 26 :)

If I downgrade MT NuGet packages to the latest stable 4.0.1 version it perfectly works and I can register up to 50 queues.

Also, another observation - with 4.1.0.1426-develop versions it takes much longer to start this very tiny app. However when I test it with latest stable 4.0.1 and try to create 50 queues it starts almost immediately.

Any ideas where this limitation came from and how to avoid it?

Questioner
Mr. Pumpkin
Viewed
0
Chris Patterson 2018-03-16 06:12:32

Thank you for opening the issue, that helps track it.

Also, it seems to be fixed now. There was an issue with how the netcoreapp2.0 program stack (and possibly the TaskScheduler) causing it to delay for a long period of time the Connect method in RabbitMQ.Client. I'm thinking this is a TPL/thread issue where the connection wasn't being scheduled for a good 15+ seconds, after which it completed immediately.

Moving it into a Task.Factory.StartNew() (deep inside the MT code) appears to have fixed the issue to where it doesn't fail, and it executes immediately.