Reputation: 2957
I have set up RabbitMQ server on my dev machine using this docker image.
I have used below command to setup my container
docker run -d --name my-rabbit -p 5672:15672 rabbitmq:3-management
Below is docker ps command output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a40704b7f3a4 rabbitmq:3-management "docker-entrypoint.s…" 13 minutes ago Up 12 minutes 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:5672->15672/tcp my-rabbit
Management console is accessible at http://localhost:5672 and I can login using default username and password ( guest/guest )
Below is my .Net Core code
public RabbitMQMnager()
{
var factory = new ConnectionFactory();
factory.Port = 5672;
Uri uri = new Uri("amqp://guest:guest@localhost:5672/");
var connection = factory.CreateConnection();
//Below are values of different connection string parameters
factory.HostName = "localhost";
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
factory.Port = 5672;
var channel = connection.CreateModel(); //<- Exception here
}
Upon executing above code, I am getting below exception.
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
Stack Trace
This exception was originally thrown at this call stack:
RabbitMQ.Client.Framing.Impl.Connection.StartAndTune()
RabbitMQ.Client.Framing.Impl.Connection.Open(bool)
RabbitMQ.Client.Framing.Impl.Connection.Connection(RabbitMQ.Client.IConnectionFactory, bool,
RabbitMQ.Client.Impl.IFrameHandler, string)
RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.Impl.IFrameHandler)
RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(RabbitMQ.Client.IEndpointResolver)
RabbitMQ.Client.ConnectionFactory.CreateConnection(RabbitMQ.Client.IEndpointResolver, string)
I found similar questions but solution mentioned there is not enough for me. It looks like it has something to do with docker and the network created by docker.
Refused connection to RabbitMQ when using docker link
Other details
RabbitMQ.Client -> 5.1.2
UPDATE 1
As per @ThisIsNoZaku answer exposing additional port solved my issue.
docker run -d --hostname my-rabbit --name my-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management
Upvotes: 7
Views: 9966
Reputation: 2443
The ports to connect to the RabbitMQ instance with an AMQP client and to connect to the management console UI (15762
in the container, which you've mapped to 5762
on the host) are different. When the application tries to point an AMQP client at the management port, it fails because it's not supported:
The management UI can be accessed using a Web browser
...
Note that the UI and HTTP API port — typically 15672 — does not support AMQP 0-9-1, AMQP 1.0, STOMP or MQTT connections. Separate ports should be used by those clients.
Your RabbitMQ instance should expose, and your client connect, to the correct ports for AMQP:
5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
Upvotes: 9