RabbitMQ works in localhost, but throws BrokerUnreachableException in LAN - (.NET Windows environment.)

I think the problem is about the UserName & Password. Follow this instruction to install and run your RabbitMQ Server.

Then browse http://localhost:15672/. This will open the RabbitMQ management login page. Add a user i.e. "abc" with password. Add all the tags shown below i.e. "administrator,management, policymaker".

Now use the following code to your client-

       var factory = new ConnectionFactory() { HostName = "192.168.100.6", Password = "123", UserName = "abc" };

        using (var connection = factory.CreateConnection())
        {
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare("hello", false, false, false, null);

                var consumer = new QueueingBasicConsumer(channel);
                channel.BasicConsume("hello", true, consumer);

                Console.WriteLine(" [*] Waiting for messages." +
                                         "To exit press CTRL+C");
                while (true)
                {
                    var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                    var body = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine(" [x] Received {0}", message);
                }
            }
        }

Hope, this will solve your problem.

Tags:

.Net

Rabbitmq