2

I'm trying to get the RabbitMQ server working. The localhost connection was not a problem with the tutorial. But whenever I try to do the same trough the network I can't get the application to connect to the broker.

Send:

var factory = new ConnectionFactory() { };
factory.HostName = "192.168.1.52";
factory.Port = 5672;
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
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();

The RabbitMQ instance runs on a different PC with the IP address 192.168.1.52. The default port used by RabbitMQ is 5672, and I've not yet changed the username or password so those are still guest and guest.

Recieve:

var factory = new ConnectionFactory() { };
factory.HostName = "192.168.1.52";
factory.Port = 5672;
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
using (var connection = factory.CreateConnection())
    using (var channel = connection.CreateModel())
    {
        channel.QueueDeclare(queue: "hello",
                             durable: false,
                             exclusive: false,
                             autoDelete: false,
                             arguments: null);

        var consumer = new EventingBasicConsumer(channel);
        consumer.Received += (model, ea) =>
        {
            var body = ea.Body;
            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();
    }

Both program's throw a exception:

Exception thrown: 'RabbitMQ.Client.Exceptions.ConnectFailureException' in RabbitMQ.Client.dll while running the program

but it doesn't break the thread. After a while the threat exitst with the following error:

ExtendedSocketException: A connection attempt failed because the connected party did not respond correctly after a certain time, or the connection made failed because the connected host did not respond. 192.168.1.52:5672

4
  • 3
    Dumb question, but have you checked the firewall settings? Commented Mar 4, 2020 at 8:20
  • 2
    I don't think it's a dumb question, and it is probably the culprit. Commented Mar 4, 2020 at 8:20
  • Cheers guys, that seemed to help. A couple of follow up questions. I've tried to find the instance off RabbitMQ in the allowed application list but there isn't one just simply called RabbitMQ. I did, however, find erl ( which I believe to be the one that needs to be allowed (lists.rabbitmq.com/pipermail/rabbitmq-discuss/2013-January/… )) but that one I already allowed. But after temporary turning off the firewall, it did throw a different error, which I will try to tackle next Commented Mar 4, 2020 at 8:44
  • @Titulum That was definitively the issue. After tackling the next error ( which was caused by using the guest guest login ) i was able to create a connection and send a message. Do you happen to know what application i need to add the the firewall accepted list inorder to make this possible without turning off the firewall? Commented Mar 4, 2020 at 9:12

3 Answers 3

6

Create a new user account, the default guest account is restricted to localhost only.

Sign up to request clarification or add additional context in comments.

1 Comment

While you're completely right ( and I have fixed this now ), I will be tagging @Titulum's answer as the correct one but making a comment there to point to your answer as well. As this was also an issue I came across after fixing the issues discribed in the question. So thank you for your answer!
3

Tu-Jen Liang is partially correct. This is what you need to do:

  • First you need to enable RabbitMq management

    rabbitmq-plugins enable rabbitmq_management

  • Second you need to create an account for rabbitmq_management, Guest doesn't have enough permissions

  • Third you need to configure the firewall to receive messages through 5672 port or the one you set up

Comments

1

The problem is probably your firewall. [RabbitMQ has some documentation on how to configure your firewall correctly so that you don't have to completely turn it off] (https://www.rabbitmq.com/networking.html#ports).

Here is the overview in case of link-rot:

Port Access

RabbitMQ nodes bind to ports (open server TCP sockets) in order to accept client and CLI tool connections. Other processes and tools such as SELinux may prevent RabbitMQ from binding to a port. When that happens, the node will fail to start.

CLI tools, client libraries and RabbitMQ nodes also open connections (client TCP sockets). Firewalls can prevent nodes and CLI tools from communicating with each other. Make sure the following ports are accessible:

    4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
    5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
    25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
    35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
    15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
    61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
    1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
    15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
    15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
    15692: Prometheus metrics (only if the Prometheus plugin is enabled)

It is possible to configure RabbitMQ to use different ports and specific network interfaces.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.