【问题标题】:RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'RabbitMQ.Client.Exceptions.BrokerUnreachableException:'指定的端点都不可到达'
【发布时间】:2021-05-23 09:09:48
【问题描述】:

我无法让 RabitMq 工作并收到此错误。我发布这个是为了让其他有同样问题的人最终可以比我更快地找到解决方案 - 我花了几个小时来找到问题的解决方案。

【问题讨论】:

    标签: c# console rabbitmq


    【解决方案1】:

    感谢@evgenirusev - https://github.com/devmentors/DNC-DShop/issues/8

    RabitMQ - Docker - https://hub.docker.com/_/rabbitmq

    我试图让 RabitMq“Hello World”教程工作,但不知道为什么它不工作。

    这对我有用: - 希望对某人有所帮助

    1.在 Docker Terminal "Client" 中制作 RabitMq Image - new Image - docker run -d --hostname my-rabit --name ecomm-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:management

    2。比我复制的 IP 是“192.168.99.100:15672”与端口:15672 并在RabitMq 中使用它作为hostname - “从码头复制kitematicapp

    3。在 RabitMQ 控制台应用程序中发送和接收 - factory.HostName = "192.168.99.100";

    4.在 RabitMQ 控制台应用程序中发送和接收 - factory.Port = AmqpTcpEndpoint.UseDefaultPort;

    5.不要忘记 - Nuget-“RabbitMQ.Client” <PackageReference Include="RabbitMQ.Client" Version="6.2.1" />

    接收:

     ConnectionFactory factory = new ConnectionFactory();
            //factory.UserName = "user";
            //factory.Password = "password";
            //factory.VirtualHost = "/";
            factory.HostName = "192.168.99.100";
            factory.Port = AmqpTcpEndpoint.UseDefaultPort;
            IConnection connection = factory.CreateConnection();
    
    
            //using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
    
                Console.WriteLine(" [*] Waiting for messages.");
    
                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var body = ea.Body.ToArray();
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", message);
                };
                channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer);
    
                Console.WriteLine(" Press [enter] to exit.");
                Console.ReadLine();
    

    发送:

        ConnectionFactory factory = new ConnectionFactory();
        //factory.UserName = "user";
        //factory.Password = "password";
        //factory.VirtualHost = "/";
        factory.HostName = "192.168.99.100";
        factory.Port = AmqpTcpEndpoint.UseDefaultPort;
        IConnection connection = factory.CreateConnection();
    
        //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();
    

    【讨论】:

      猜你喜欢
      • 2020-07-20
      • 2020-11-25
      • 1970-01-01
      • 2015-12-02
      • 1970-01-01
      • 2021-04-09
      • 2018-05-31
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多