RabbitMQ with Docker on Windows in 30 minutes
How to set up a RabbitMQ instance with Docker on Windows and start sending messages.
Want to quickly spin up RabbitMQ on your Windows development environment? Maybe you just want to try the most deployed message broker and you don’t want to try it on Azure or ask your IT crew to deploy a new server just for that: Docker is your solution.
- Install Docker for Windows: just download it and let the installer do the rest
- Start Docker and wait for its the initialization. You will see an icon of a whale in the taskbar
- Open Powershell and type:
If you don’t see any errors, and you see a Docker version, it is correctly installed.
4. Now we have to download the RabbitMQ image. In this case, we will download the image with a management plugin in order to be able to view the RabbitMQ server-side GUI. The command to download or update a Docker image is
5. Now we will start the RabbitMQ Docker image with a simple command:
p argument we are mapping RabbitMQ ports to Docker container ports. 15672 is the default port for RabbitMQ GUI, 5672 for RabbitMQ message broker. With the
name argument we are giving a name to our container, in order to identify it in a more readable way than using the generated GUID. This will allow us to easily stop, remove, and manage our containers. At the end, we specify the docker image to run, in this case the one we pulled before.
If the operation goes well, you will see a GUID as output.
6. Test the image by opening “http://localhost:15672/#/” in your browser. The default login is
guest: you should see the RabbitMQ management GUI.
If you see this page correctly, the most important part is done!
7. Now we are ready to send messages to our RabbitMQ endpoint! In this phase the choice is yours: I work daily with .NET so I will show you a C# example. Just to remind you, the default values to connect to the endpoint with your preferred language:
In my case, I will create a new Windows Console Application, install
RabbitMQ.Client Nuget package and write some lines of code to create a queue and send a message every 500 milliseconds:
In this case, I’m using a little cheat related to RabbitMQ: I’m sending messages directly to the queue without setting a binding to an exchange, by setting the routing key of the publish method with the same name as the queue I declared.
8. At the end, we want to be sure that the messages are correctly received by the queue. We can just open our management GUI, click on
Queues navigation button, then
testqueue. If we are sending messages we will see the chart's lines moving:
Also, you can click on the
Get messages menu to grab a message from the queue and read its body:
I don’t have the experience to say how Docker is on production environments, but in test/study environments, I think that Docker is really a time saving infrastructure!