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

RabbitMQ Exception 'None of the specified endpoints were reachable'

发布于 2021-01-02 16:49:14

I followed a tutorial on RabbitMQ and got stuck at an exception that occurs when creating the connection. The whole method is shown below:

class Program
{
    static void Main(string[] args)
    {
        var factory = new ConnectionFactory { Uri = new Uri("amqp://guest:guest@localhost:15672/") };
        using var connection = factory.CreateConnection();
        using var channel = connection.CreateModel();
        channel.QueueDeclare("demo-queue",
            durable: true,
            exclusive: false,
            autoDelete: false,
            arguments: null);

        var consumer = new EventingBasicConsumer(channel);
        consumer.Received += (sender, e) =>
        {
            var body = e.Body.ToArray();
            var message = Encoding.UTF8.GetString(body);
            Console.WriteLine(message);
        };
        channel.BasicConsume("demo-queue", true, consumer);
    }
}

On this line: using var connection = factory.CreateConnection(); I am getting this:

RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'

And three inner exceptions:

ExtendedSocketException: No connection could be made because the target machine actively refused it. 127.0.0.1:15672

ConnectFailureException: Connection failed

AggregateException: One or more errors occurred. (Connection failed)

What is the cause of this exception? Is the Uri wrong or not set up correctly beforehand? RabbitMQ seems to be working well as I could log into http://localhost:15672/ and it's up and running.

Thank you in advance.

EDIT: I put 5672 as the port in the Uri and the result is the same.

Questioner
Questieme
Viewed
0
Questieme 2021-01-03 01:07:52

After turning the firewall off, it started working.