Connecting to RabbitMQ on EC2 from an external client

Similar questions were asked by RabbitMQ on Amazon EC2 Instance and on-premises? and also Can't connect from my desktop to rabbitmq on ec2 But they get different error messages.

I have a RabbitMQ server running on my Linux EC2 instance that is configured correctly. I created custom users and gave them read / write permissions on the queue. Using a local client, I can receive messages correctly. I have configured security groups on EC2 so that ports (5672/25672) are open and can telnet to those ports. I also installed rabbitmq.conf like this.

[
    {rabbit, [
            {tcp_listeners, [{"0.0.0.0",5672}]},
            {loopback_users, []},
            {log_levels, [{connection, info}]}
            ]
    }
].

      

At the moment I have a client on the server that is being queued.

I have another client running on a server outside EC2 that needs to consume data from the same queue (I cannot run both on EC2 as consuming does a lot of charting / graphing manipulation).

When I try to connect, however, from an external client using some test code

try {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUri("amqp://****:****@****:5672/");
    connection = factory.newConnection();
} catch (IOException e) {
    e.printStackTrace();

      

}

I am getting the following error.

com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was rejected using PLAIN authentication mechanism. See the broker log file for more information.

However, there is nothing in the broker's log file, as if I have never tried to connect. I tried to connect using individual getter / setter factory methods, I tried different ports (along with opening them).

I was wondering if I need to use SSL or not connect to EC2, but from reading over the net it seems like it should work, but I'm not entirely sure. I cannot find examples of how people successfully achieve what I am trying to do and documenting.

Thank you in advance

+3


source to share


1 answer


The answer was simply that I needed to indicate that the host is the same IP that I am using for SSH. I was trying to use the Elastic IP / public dns of an EC2 instance, which I thought should point to the same machine.

Although I tried many things, including setting up an SSL connection, it was not necessary.



Everything you need:

  • Create rabbitmq user with rabbitmqctrl and give it appropriate permissions.
  • Open the required ports in EC2 via the security groups menu (5672 by default)
  • Use a client library to connect to the correct hostname / username / password / port, where the hostname is the same as the machine you normally SSH on.
+2


source







All Articles