Message broker
RABBITMQ Exchange messages between tasks
Sending messages and rabbits are Mihalis Tsoukalos favourite things, so he’s in Python heaven explaining how to use both.
OUR EXPERT
Mihalis Tsoukalos is a systems engineer and a technical writer. He’s also the author of Go Systems Programming and Mastering Go.
R
abbitMQ is an open source message broker. It’s ideal for exchanging information asynchronously, when you need a place where messages can be stored safely until they’re read. RabbitMQ enables you to exchange information, which is the main reason that you don’t need to use it directly unless you have to perform administrative tasks. As a result, this tutorial will show you how to develop command line utilities in Go and Python that interact with RabbitMQ.
You can install RabbitMQ using your favourite Linux package manager. However, this tutorial is going to use RabbitMQ with the help of a Docker image, which is the recommended method of running RabbitMQ because it’s portable and easy to configure.
You can obtain a RabbitMQ Docker image by executing docker pull rabbitmq:3.8-management . Although RabbitMQ doesn’t come with a graphical interface (because you don’t usually interact with it directly), this particular Docker image comes with the RabbitMQ management plugin (www.rabbitmq.com/management.html) installed, which gives you extra management capabilities through an informative and easy-to-use user interface. We’ll cover the management plugin in the next section.
Docking complete
The best way to use the RabbitMQ Docker image is by creating a docker-compose.yml file and setting it up appropriately. The following output shows the RabbitMQ configuration found in docker-compose.yml that’s used in this tutorial.
Th e code
Get it from linu xformat. com/archives
This shows a screen from the user interface of the RabbitMQ Management plugin. This give you a decent overview of your RabbitMQ installation and enables you to perform administrative tasks.
The previous configuration sets both the default RabbitMQ username and password to guest and “sets” the AMQP URL to amqp://rabbit?connection_ attempts=5&retry_delay=5. By default, RabbitMQ listens to port number 5672. Additionally, the management plugin listens to port number 15672, which means that you can access it at http:// localhost:15672/ from the machine that you executed the docker-compose up command.
You can now run docker-compose up to run the configuration described in docker-compose.yml. After that, you can connect to the running RabbitMQ container by running docker exec -it rabbit bash .
The screenshot (above) shows the UI of the management plugin that comes with the rabbitmq:3.8- management Docker image. Feel free to play around with the various settings.