简体   繁体   中英

Rabbitmq connection refused , runs inside docker container on a linux server

We have a problem connecting to the RabbitMQ server which runs in docker on a Linux server. I'm am using the following code to connect.

    factory = new ConnectionFactory();
    factory.setUsername("name");
    factory.setPassword("password");
    factory.setHost("ip host");

    connection = factory.newConnection();
    channel = connection.createChannel();

The password and username have been guest/guest as default, but another was also tried which I'm not specifying in here. Was reading about guest/guest couldn't be used for the remote connection.

The problem is that we are getting a "java.net.ConnectException: Connection refused: connect"

Have installed rabbitMQ on my local laptop, where instead of our Linux server IP + port that can be used to reach RabbitMQ on the server, "localhost" was tried which works fine.

Problem is that we need to use the server, as we are going to test there.

So something blocks from request to get a connection. I have tried to search for similar posts, but nothing seems to work, and everyone is simple using localhost, which works fine.

Should also be set that im using Java in Eclipse trying to connect to rabbitmq.

I managed to solve the problem.

Basically what was needed was the correct port 5672 to be opened, and not just 15672.

docker run -d -p 5672:5672 -p 15672:15672  --name rabbitmq rabbitmq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM