In this article, you will learn to set up a RabbitMQ server for the development purpose using docker-compose. We will download the official rabbitmq
docker image, run it.
Prerequisites (Docker)
- Docker, minimum installed version –
2.0
. - Docker-compose, minimum installed version –
1.23
.
1. Installation of RabbitMQ – docker-compose
Step-1) Make sure you have the docker installed in your system by running the below commands.
$ docker -v Docker version 19.03.5, build 633a0ea $ docker-compose -v docker-compose version 1.24.1, build 4667896b
Step-2) Create a docker-compose.yaml
file with the below content.
version: "3.6"
# https://docs.docker.com/compose/compose-file/
services:
rabbitmq:
image: 'rabbitmq:3.6-management-alpine'
ports:
# The standard AMQP protocol port
- '5672:5672'
# HTTP management UI
- '15672:15672'
environment:
# The location of the RabbitMQ server. "amqp" is the protocol;
# "rabbitmq" is the hostname. Note that there is not a guarantee
# that the server will start first! Telling the pika client library
# to try multiple times gets around this ordering issue.
AMQP_URL: 'amqp://rabbitmq?connection_attempts=5&retry_delay=5'
RABBITMQ_DEFAULT_USER: "guest"
RABBITMQ_DEFAULT_PASS: "guest"
networks:
- network
networks:
# Declare our private network. We must declare one for the magic
# Docker DNS to work, but otherwise its default settings are fine.
network: {}
Step-3)
Run the docker-compose up
command in a terminal, wait for the command to complete its execution. This will download the specified rabbitmq docker image, run the rabbitmq-admin UI on #15672 and the Server listens on #5672 for messaging. Once the server is up, you will see a similar log in your terminal.
rabbitmq_1 | =INFO REPORT==== 10-Mar-2020::16:11:17 === rabbitmq_1 | started TCP Listener on [::]:5672 rabbitmq_1 | rabbitmq_1 | =INFO REPORT==== 10-Mar-2020::16:11:17 === rabbitmq_1 | Management plugin started. Port: 15672 rabbitmq_1 | rabbitmq_1 | =INFO REPORT==== 10-Mar-2020::16:11:17 === rabbitmq_1 | Statistics database started. rabbitmq_1 | completed with 6 plugins. rabbitmq_1 | rabbitmq_1 | =INFO REPORT==== 10-Mar-2020::16:11:18 === rabbitmq_1 | Server startup complete; 6 plugins started. rabbitmq_1 | * rabbitmq_management rabbitmq_1 | * rabbitmq_web_dispatch rabbitmq_1 | * cowboy rabbitmq_1 | * rabbitmq_management_agent rabbitmq_1 | * amqp_client
Step-4) Login
Navigate to http://localhost:15672 in your browser and log in to the management dashboard with guest
as both username and password. You should be able to see the RabbitMQ admin management dashboard as shown below. I have overridden the username and password as rabbitmq by changing the properties RABBITMQ_DEFAULT_USER
and RABBITMQ_DEFAULT_PASS
in the above docker-compose.yml
file. You can just keep the username and password unchanged.
If you are able to see the above UI, it means the installation is successful. I will add the installation guides on Windows, Mac, and Linux a little later.
2. Install on Windows
Here are the updated steps with the correct URLs and more precise instructions for installing RabbitMQ on Windows:
Steps to Install RabbitMQ on Windows
RabbitMQ requires Erlang to be installed first.
Step 1: Download Erlang
- Visit the Erlang Downloads page.
- Under the “Windows” section, download the installer that matches your system architecture (32-bit or 64-bit).
Step 2: Install Erlang
- Run the downloaded installer.
- Follow the installation prompts and accept the default settings.
- Ensure that the installation path is added to the system’s PATH environment variable (this is usually done automatically by the installer).
Step 3: Download RabbitMQ
- Go to the RabbitMQ Downloads page.
- Under the “Installing RabbitMQ on Windows” section, find the link to download the RabbitMQ installer for Windows.
Step 4: Install RabbitMQ
- Run the downloaded RabbitMQ installer.
- Follow the installation prompts and accept the default settings.
- The installer will place RabbitMQ files in the
C:\Program Files\RabbitMQ Server
directory by default.
Step 5: Set RABBITMQ_SERVER
Environment Variable
- Open the Windows Control Panel and go to System and Security > System > Advanced system settings.
- Click on Environment Variables.
- Under System variables, click New and create a new variable:
- Variable name:
RABBITMQ_SERVER
- Variable value:
C:\Program Files\RabbitMQ Server\rabbitmq_server-<version>
(replace<version>
with the installed version number).
Step 6: Enable the Management Plugin
- Open a Command Prompt window as an administrator.
- Navigate to the RabbitMQ
sbin
directory:cd C:\Program Files\RabbitMQ Server\rabbitmq_server-<version>\sbin
. - Run the following command to enable the management plugin:
rabbitmq-plugins enable rabbitmq_management
Step 7: Start RabbitMQ Server
- In the same Command Prompt window, start the RabbitMQ server by running:
rabbitmq-server.bat
- Alternatively, you can start the RabbitMQ server as a Windows service:
rabbitmq-service install
rabbitmq-service start
Step 8: Access the Management UI
- Open a web browser and go to
http://localhost:15672
. - The default login credentials are:
- Username:
guest
- Password:
guest
Summary
By following these steps, you should have RabbitMQ installed and running on your Windows system. You can now use the management interface to configure RabbitMQ, create queues, exchanges, and manage your messaging setup.
Note
Ensure that you download the correct versions of Erlang and RabbitMQ that are compatible with each other. The RabbitMQ installation guide usually specifies the compatible Erlang versions.
3. Install RabbitMQ on macOS
1. Install Homebrew
Homebrew is a package manager for macOS that makes it easy to install software. If you don’t have Homebrew installed, you can install it by running the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install Erlang
RabbitMQ requires Erlang to be installed first. You can install Erlang using Homebrew:
brew install erlang
3. Install RabbitMQ
Once Erlang is installed, you can install RabbitMQ using Homebrew:
brew install rabbitmq
4. Start RabbitMQ Server
After installing RabbitMQ, you need to start the RabbitMQ server:
brew services start rabbitmq
This command will start RabbitMQ as a background service that will automatically start when your computer boots up.
5. Enable the RabbitMQ Management Plugin
To manage RabbitMQ through a web interface, you need to enable the management plugin:
rabbitmq-plugins enable rabbitmq_management
6. Access RabbitMQ Management Interface
Once the management plugin is enabled, you can access the RabbitMQ management interface:
- Open a web browser and go to
http://localhost:15672
. - The default login credentials are:
- Username:
guest
- Password:
guest
7. Verify Installation
To verify that RabbitMQ is running, you can use the following command:
rabbitmqctl status
This command will provide information about the running RabbitMQ server.
By following these steps, you should have RabbitMQ installed and running on your macOS system. The management interface will help you configure RabbitMQ, create queues, exchanges, and manage your messaging setup. Using Homebrew simplifies the installation process and ensures that dependencies like Erlang are correctly installed.