尝试在 c# 中连接到 rabbitMQ 但得到 BrokerUnreachable

在按照他们网站上的教程到下面是我的代码之后,我无法连接到 rabbitMQ 服务器。


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

    using(var connection = factory.CreateConnection())

    using(var channel = connection.CreateModel())

    {

        channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);


        string message = "Hello World!";

        var body = Encoding.UTF8.GetBytes(message);


        channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body);

        Console.WriteLine(" [x] Sent {0}", message);

    }


    Console.WriteLine(" Press [enter] to exit.");

    Console.ReadLine();


收到一只叮咚
浏览 293回答 1
1回答

慕盖茨4494581

BrokerUnreachableException表示客户端无法访问服务器。检查服务器是否实际启动并运行,或者您是否有一些防火墙配置。有几篇关于的帖子BrokerUnreachableException,例如关注这个关于那个的帖子
打开App,查看更多内容
随时随地看视频慕课网APP