Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send message in rabbitmq on docker?

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?

like image 474
Olegs Jasjko Avatar asked Nov 15 '17 13:11

Olegs Jasjko


People also ask

How do I use Rabbitmq with docker?

Open a terminal, navigate to your rabbitmq-go folder and run docker-compose up . This command will pull the rabbitmq:3-management-alpine image, create the container rabbitmq and start the service and webUI. You should see something like this: Once you see this, open your browser and head over to http://localhost:15672.

How do I change my Rabbitmq docker username and password?

If you wish to change the default username and password of guest / guest , you can do so with the RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS environmental variables. These variables were available previously in the docker-specific entrypoint shell script but are now available in RabbitMQ directly.

What is a docker compose?

Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.


2 Answers

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.

like image 68
Evk Avatar answered Sep 19 '22 17:09

Evk


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

like image 21
Artur Karbone Avatar answered Sep 17 '22 17:09

Artur Karbone