2

我正在使用互联网上提供的示例代码,但我遇到了一个异常,我无法解决这个错误。

我得到了这个例外

BrokerUnreachableExceptionCaught 指定的端点均不可到达

不知道如何解决此错误。有很多链接发布了遇到错误,但没有一个有它的解决方案。请帮助我解决这个问题。您的建议将对我有所帮助。请尽快提供帮助。

一些链接

代码:

try
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.UserName = "user";
    factory.Password = "password";
    factory.VirtualHost = "/";
    factory.Protocol = Protocols.FromEnvironment();
    factory.HostName = "localhost";
    factory.Port = AmqpTcpEndpoint.UseDefaultPort;
    IConnection conn = factory.CreateConnection();

    //using (var connection = factory.CreateConnection())
    //{
    //    using (var channel = connection.CreateModel())
    //    {
    //        channel.QueueDeclare("hello", false, false, false, null);
    //        string message = "Hello World!";
    //        var body = Encoding.UTF8.GetBytes(message);

    //        channel.BasicPublish("", "hello", null, body);
    //        Console.WriteLine(" [x] Sent {0}", message);
    //    }
    //}
}
catch
{
}
4

2 回答 2

3

抛出的 BrokerUnreachableException 具有以下有用的属性:

ConnectionAttempts ConnectionErrors

查看这些以查看是否有任何额外信息(例如,密码可能不正确。)

于 2013-09-22T22:13:30.827 回答
0

Asp.net core 中的 RabbitMQ localhost 连接,在 Nugget Package 中,浏览RabbitMQ.Client

//localhost 连接,这些都对我有用。

var factory = new ConnectionFactory() { HostName = "localhost" };

或者

var factory = new ConnectionFactory();

using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "HelloNewWorld",
                             durable: false,
                             exclusive: false,
                             autoDelete: false,
                             arguments: null);
                             
                             string message = "Hello World!";
        var body = Encoding.UTF8.GetBytes(message);

        channel.BasicPublish(exchange: "",
                             routingKey: "HelloNewWorld",
                             basicProperties: null,
                             body: body);
        Console.WriteLine(" [x] Sent {0}", message);
            }
        
        }

//default localhost for rabbitmq
http://localhost:15672/queues

在此处输入图像描述

Asp.NetCore #RabbitMQ

于 2019-06-12T14:42:54.390 回答