RabbitMQ is an open-source message broker software. It’s a software where queues are defined and to which applications connect in order to transfer a message or messages. Think of it as a middle man who acts as a broker. They can be used to reduce loads and delivery times for web application servers by delegating tasks that take up a lot of resources and or time to a third party that has no other job
Reasons for Using RabbitMQ
Message queueing allows web servers to respond to requests quickly instead of being forced to perform resource-heavy procedures on the spot that may cause delays.
Message queueing is important when you want to distribute a message to multiple consumers and also to balanced loading between worker nods.
Installing RabbitMQ 3.9 on Ubuntu 22.04
RabbitMQ is included in Ubuntu repositories but it lacked behind in terms of version releases. It is not the updated version because it takes longer to be updated.
1. Update system repositories
We need to start off by updating our repositories to make them up to date.
sudo apt update && apt upgrade -y
2. Install Erlang
Erlang/OTP platform is a complex system consisting of many smaller modules. RabbitMQ requires Erlang to operate.
Let’s start by adding Erlang to the repository manually. Use the following commands:
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
sudo dpkg -i erlang-solutions_2.0_all.deb
Next, we need to add Erlang public key to the apt-secure repository.
wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
sudo apt-key add erlang_solutions.asc
Lastly is to install Erlang but first run the system update again for the changes to take effect.
sudo apt update
sudo apt install erlang -y
3. Install RabbitMQ on Ubuntu 22.04
Now that we have satisfied all the requirements, we can now install RabbitMQ found on Ubuntu repositories with the following command.
sudo apt install rabbitmq-server -y
You will get the following output.
The following NEW packages will be installed:
rabbitmq-server socat
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 15.5 MB of archives.
After this operation, 24.3 MB of additional disk space will be used.
Get:1 http://mirrors.digitalocean.com/ubuntu jammy/main amd64 socat amd64 1.7.4.1-3ubuntu4 [349 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu jammy/main amd64 rabbitmq-server all 3.9.13-1 [15.2 MB]
Fetched 15.5 MB in 0s (37.3 MB/s)
Selecting previously unselected package socat.
(Reading database ... 114923 files and directories currently installed.)
Preparing to unpack .../socat_1.7.4.1-3ubuntu4_amd64.deb ...
Unpacking socat (1.7.4.1-3ubuntu4) ...
Selecting previously unselected package rabbitmq-server.
Preparing to unpack .../rabbitmq-server_3.9.13-1_all.deb ...
Unpacking rabbitmq-server (3.9.13-1) ...
Setting up socat (1.7.4.1-3ubuntu4) ...
Setting up rabbitmq-server (3.9.13-1) ...
Adding group `rabbitmq' (GID 122) ...
Done.
Adding system user `rabbitmq' (UID 114) ...
Adding new user `rabbitmq' (UID 114) with group `rabbitmq' ...
Not creating home directory `/var/lib/rabbitmq'.
Created symlink /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service → /lib/systemd/system/rabbitmq-server.service.
Processing triggers for man-db (2.10.2-1) ...
Use apt cache-policy rabbitmq-server to check your installed RabbitMQ.
apt cache-policy rabbitmq-server
You will see the following output.
#output
rabbitmq-server:
Installed: 3.9.13-1
Candidate: 3.9.13-1
Version table:
*** 3.9.13-1 500
500 http://mirrors.digitalocean.com/ubuntu jammy/main amd64 Packages
100 /var/lib/dpkg/status
4. Configuring RabbitMQ
After installation is complete, we now need to do some configuration on RabbitMQ.
First, start the RabbitMQ service with the following command.
sudo systemctl start rabbitmq-server
Check the status if RabbitMQ is running with the following command:
$ sudo systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ Messaging Server
Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-29 19:38:53 UTC; 2min 35s ago
Main PID: 17434 (beam.smp)
Tasks: 21 (limit: 1119)
Memory: 108.8M
CPU: 8.051s
CGroup: /system.slice/rabbitmq-server.service
├─17434 /usr/lib/erlang/erts-12.2.1/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 10485>
├─17445 erl_child_setup 65536
├─17492 inet_gethost 4
└─17493 inet_gethost 4
lines 1-12/12 (END)
Enable RabbitMQ on boot so that you don’t need to start every time when you reboot your system.
sudo systemctl enable rabbitmq-server
5. Enable RabbitMQ dashboard. (Optional)
You can enable dashboard management for RabbitMQ with the following command.
sudo rabbitmq-plugins enable rabbitmq_management
You will get the following output.
Enabling plugins on node [email protected]:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to [email protected]...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
started 3 plugins.
You can now access the dashboard using http://
15672 is the port RabbitMQ is served into.
You can create an admin login or you can use the quest if you only want to see what’s in it but if you want to do some operations, you will need to create the admin.
$ sudo rabbitmqctl add_user admin passwd
Adding user "admin" ...
Password:
passwd
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
$ sudo rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...
Conclusion
We have successfully installed RabbitMQ on Ubuntu 22.04. To know more on the management commands head over to RabbitMQ getting started. I hope you enjoyed and thank you for reading.