8

Again, it supposed to be simple, but wasn't able to find any documentation about it

In my previous question I had a problems with running rabbitmq container in docker. It has been solved, but now another one appeared

Container was created with this line

docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 rabbitmq:3-management

I was trying to create a simple console application to check how message sending is working (from base tutorial):

var factory = new ConnectionFactory()
{
  HostName = "localhost",
  Port = 15672
};

using (var connection = factory.CreateConnection())
{
  using (var channel = connection.CreateModel())
  {
    channel.QueueDeclare("Test", false, false, false, null);

    var mess = new RepMessage()
    {
       ConnectionString = "TestingString",
       QueueID = 5
    };

    var jsonified = JsonConvert.SerializeObject(mess);
    var messBody = Encoding.UTF8.GetBytes(jsonified);
    channel.BasicPublish("", "Test", null, messBody);

    Console.WriteLine(string.Format("Message with ConStr={0}, QueueID={1} has been send", mess.ConnectionString, mess.QueueID));
  }
}

And result is, its not working. I am receiving exception None of the specified endpoints were reachable and inner exception as connection.start was never received, likely due to a network timeout

If I remove port, then my inner exception transforms in No connection could be made because the target machine actively refused it 127.0.0.1:5672

What am I missing, is is this example not supposed to work with docker?

Olegs Jasjko
  • 2,128
  • 6
  • 27
  • 47

2 Answers2

13

Port 15672 is a port of rabbitmq management plugin web interface. When you are sending message to rabbit - you need to connect to different port (by default - 5672). So change your code to connect to that port and map it in docker via -p 5672:5672.

Evk
  • 98,527
  • 8
  • 141
  • 191
4

In your particular case docker command would look like this

docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Artur Karbone
  • 1,456
  • 13
  • 11