Connect to RabbitMQ on EC2 from external client

4.8k views Asked by At

Similar questions have been asked RabbitMQ on Amazon EC2 Instance & Locally? and cant 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 which is set up correctly. I have created custom users and given them permissions to read/write to queues. Using a local client I am able to correctly receive messages. I have set up the security groups on EC2 so that ports (5672/25672) are open and can telnet to those ports. I also have set up 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 publishing to the queue.

I have another client running on a server outside of EC2 which needs to consume data from the same queue (I can't run both on EC2 as the consume does a lot of plotting/graphical manipulation).

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

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

}

I get the following error.

com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

However there is nothing in the broker logfile as if I never tried to connect. I've tried connecting using the individual getter/setter methods of factory, I've tried using different ports (along with opening them up).

I was wondering if I need to use SSL or not to connect to EC2 but from reading around the web it seems like it should just work but I'm not exactly sure. I cannot find any examples of people successfully achieving what I'm trying to do and documenting it.

Thanks in advance

1

There are 1 answers

1
Paul P M On BEST ANSWER

The answer was simply that I needed to specify the host to be the same IP I use to SSH into. I was trying to use the Elastic IP/public dns of the instance of the EC2 instance which I thought should point to the same machine.

Although I did try many things including setting up an SSL connection it was not necessary.

All that is needed is:

  1. Create rabbitmq user using rabbitmqctrl and give it appropriate permissions
  2. Open the needed ports on EC2 via Security Groups menu (default is 5672)
  3. Use client library to connect to correct host name/username/password/port where the host name is the same as the machine that you normally SSH into.