RabbitMQ 异常 'None of the specified endpoints were reachable'
RabbitMQ Exception 'None of the specified endpoints were reachable'
我按照有关 RabbitMQ 的教程进行操作,但卡在了创建连接时发生的异常。整个方法如下图:
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);
}
}
这一行:using var connection = factory.CreateConnection();
我得到这个:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
以及三个内部异常:
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)
这个异常的原因是什么? Uri 是否错误或事先设置不正确? RabbitMQ 似乎运行良好,因为我可以登录 http://localhost:15672/ 并且它已经启动 运行.
提前致谢。
编辑:我将 5672 作为 Uri 中的端口,结果是一样的。
关闭防火墙后,它开始工作了。
我按照有关 RabbitMQ 的教程进行操作,但卡在了创建连接时发生的异常。整个方法如下图:
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);
}
}
这一行:using var connection = factory.CreateConnection();
我得到这个:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
以及三个内部异常:
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)
这个异常的原因是什么? Uri 是否错误或事先设置不正确? RabbitMQ 似乎运行良好,因为我可以登录 http://localhost:15672/ 并且它已经启动 运行.
提前致谢。
编辑:我将 5672 作为 Uri 中的端口,结果是一样的。
关闭防火墙后,它开始工作了。