A message is data that needs to get processed into information. A queue is a line of things that are processed sequentially. Message queueing is a form of asynchronous communication protocol that allows applications to exchange information by sending messages to each other. It stores messages temporarily if the destination program is busy or not connected. Think of an email sent to a user who is not connected or is busy to reply. The email is stored until the user is connected or replies to it. Messaging increases loose coupling and scalability.

RabbitMQ standing for Rabbit Message Queue is an open-source message broker software that defines queues to which applications connect to send a message. RabbitMQ implements the AMQP (Advanced Message Queuing Protocol). It acts as a middleman that reduces loads of servers by delegating tasks and operations that take up a lot of resources to a third party that has no job. It is lightweight and can be deployed on-premises and in the cloud. It can be used by small startups and large enterprises.

Features of RabbitMQ

  • Supports Asynchronous Messaging with multiple messaging protocols.
  • Deploy applications with Kubernetes and Docker.
  • Develop cross-messaging with different programming languages.
  • Can be deployed in distributed configurations to meet high availability and throughput.
  • Has a diverse array of tools and plugins for continuous integration.
  • Has a command-line tool and Web UI for managing the software.

This guide will show you how to set up RabbitMQ on CentOS 9|AlmaLinux 9|RHEL 9 systems.

#1) Install RabbitMQ on CentOS 9|AlmaLinux 9|RHEL 9

Set the crypto policies to LEGACY to ensure compatibility.

sudo update-crypto-policies --set LEGACY

Then restart your system to apply changes.

sudo reboot

We will install RabbitMQ with a YUM repository that contains the package.

sudo dnf -y install wget
wget https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh -O rabbitmq_script.rpm.sh
chmod +x  rabbitmq_script.rpm.sh
sudo os=el dist=8 ./rabbitmq_script.rpm.sh

Next is to add the YUM repository under the /etc/yum.repos.d/ directory that will install RabbitMQ and its Erlang dependency from PackageCloud.

wget https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh -O erlang_script.rpm.sh
chmod +x  erlang_script.rpm.sh
sudo os=el dist=8 ./erlang_script.rpm.sh

Update the system after installing the repositories required.

sudo yum update -y

Install the package dependencies with the following commands.

sudo yum install socat logrotate -y

Now install Erlang and RabbitMQ.

sudo yum install rabbitmq-server erlang

Accept installation of the packages.

Dependencies resolved.
 Package                                         Architecture                          Version                                          Repository                                               Size
 erlang                                          x86_64                                25.0.2-1.el8                                     rabbitmq_erlang                                          20 M
 rabbitmq-server                                 noarch                                3.10.6-1.el8                                     rabbitmq_rabbitmq-server                                 14 M
Installing dependencies:
 compat-openssl11                                x86_64                                1:1.1.1k-4.el9_0                                 appstream                                               1.5 M

Transaction Summary
Install  3 Packages

Total download size: 36 M
Installed size: 59 M
Is this ok [y/N]: y

Start and enable the service at boot time.

sudo systemctl enable --now rabbitmq-server

Check the status of the server.

$ systemctl status rabbitmq-server
 rabbitmq-server.service - RabbitMQ broker
     Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
     Active: active (running) since Sat 2022-07-30 04:11:07 EAT; 6s ago
   Main PID: 2141 (beam.smp)
      Tasks: 24 (limit: 48943)
     Memory: 101.1M
        CPU: 4.397s
     CGroup: /system.slice/rabbitmq-server.service
             ├─2141 /usr/lib64/erlang/erts-13.0.2/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdc>
             ├─2154 erl_child_setup 32768
             ├─2179 /usr/lib64/erlang/erts-13.0.2/bin/epmd -daemon
             ├─2200 /usr/lib64/erlang/erts-13.0.2/bin/inet_gethost 4
             └─2201 /usr/lib64/erlang/erts-13.0.2/bin/inet_gethost 4

Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Doc guides:  https://rabbitmq.com/documentation.html
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Support:     https://rabbitmq.com/contact.html
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Tutorials:   https://rabbitmq.com/getstarted.html
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Monitoring:  https://rabbitmq.com/monitoring.html
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Logs: /var/log/rabbitmq/[email protected]
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:         /var/log/rabbitmq/[email protected]_upgrade.log
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:         <stdout>
Jul 30 04:11:05 alma9.mylab.io rabbitmq-server[2141]:   Config file(s): (none)
Jul 30 04:11:07 alma9.mylab.io rabbitmq-server[2141]:   Starting broker... completed with 0 plugins.
Jul 30 04:11:07 alma9.mylab.io systemd[1]: Started RabbitMQ broker.

Configure Firewall to allow RabbitMQ port.

sudo firewall-cmd --add-port=5672/tcp --permanent
sudo firewall-cmd --reload

#2) Managing User Accounts in RabbitMQ

To add a user, use the following command. here ‘technixleo‘ is the name of the user I want to add with the password.

$ sudo rabbitmqctl add_user technixleo StrongPassW0rd
Adding user "technixleo" ...

Verify the user has been created by listing the users.

$ sudo rabbitmqctl list_users
Listing users ...
user	tags
technixleo	[]
guest	[administrator]

To change a password for a user, use the following command.

$ rabbitmqctl change_password technixleo NewUserPassw0rd
Changing password for user "technixleo" ...

Grant Admin role to a user.

$ sudo rabbitmqctl set_user_tags technixleo administrator
Setting tags for user "technixleo" to [administrator] ...

To delete a user.

rabbitmqctl delete_user technixleo

#3) Create VirtualHost for RabbitMQ

To add a virtual host, use the following command.

$ sudo rabbitmqctl add_vhost /vhost01
Adding vhost "/vhost01" ...

Check to see if it has been created.

$ sudo rabbitmqctl list_vhosts
Listing vhosts ...

Grant permission to a user for a virtual host. the permissions are; modify, write and read and are represented by the asterisk * symbol on the following command.

$ sudo rabbitmqctl set_permissions -p /vhost01 technixleo ".*" ".*" ".*"
Setting permissions for user "technixleo" in vhost "/vhost01" ...

Show permissions for the virtual host as shown below.

$ sudo rabbitmqctl list_permissions -p /vhost01
Listing permissions for vhost "/vhost01" ...
user	configure	write	read
technixleo	.*	.*	.*

To show permissions of the virtual host for a specific user.

$ sudo rabbitmqctl list_user_permissions technixleo
Listing permissions for user "technixleo" ...
vhost	configure	write	read
/vhost01	.*	.*	.*

To delete permissions of a specific user for a virtual host, use the following command.

rabbitmqctl clear_permissions -p /vhost01 technixleo

To delete a virtual host, use the following command.

rabbitmqctl delete_vhost /vhost01

#4) Enable RabbitMQ Web UI

Enable the Management Plugin

$ sudo rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node [email protected]:
The following plugins have been configured:
Applying plugin configuration to [email protected]
The following plugins have been enabled:

started 3 plugins.

Restart the server

sudo systemctl restart rabbitmq-server

Access the Web UI using http://server-ip-address:15672 on any client. Then log in using the user account you created.

The dashboard appears as shown below.

#5) Install and use rabbitmqadmin

rabbitmqadmin is a Python command-line tool that interacts with the HTTP API. It uses the same API as RabbitMQ and provides access to a subset of functionalities in the UI from the command line.

Install Python if you do not have it on your system.

sudo yum -y install python3

Check for the version to verify the installation.

$ python3 -V
Python 3.9.10

To install rabbitmqadmin, Login to Web UI and move to http://server-IP address:15672/cli

Click on Download it and select Save File.

Make the file executable and drop it on your path

cd Downloads
sudo mv rabbitmqadmin /usr/local/bin
sudo chmod +x /usr/local/bin/rabbitmqadmin
export PATH="/usr/local/bin:${PATH}"

Check Permission settings

$ sudo ls -l /usr/local/bin/rabbitmqadmin
-rwxr-xr-x. 1 technixleo technixleo 42416 Jul  1 00:40 /usr/local/bin/rabbitmqadmin

Basic rabbitmqadmin commands

To list users

$ rabbitmqadmin list users
|    name    |       hashing_algorithm        |                  password_hash                   |     tags      |
| guest      | rabbit_password_hashing_sha256 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | administrator |
| technixleo | rabbit_password_hashing_sha256 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | administrator |

To list the available virtual hosts

$ rabbitmqadmin list vhosts
|   name   | messages |
| /        |          |
| /vhost01 |          |

To create a user.

$ rabbitmqadmin declare user name=technix password=PassWord tags=administrator
user declared

To create a virtual host

$ rabbitmqadmin declare vhost name=/vhost02
vhost declared

To grant permission to a user for a virtual host.

$ rabbitmqadmin declare permission vhost=/vhost02 user=technix configure=".*" write=".*" read=".*"
permission declared

To add a message queue.

$ rabbitmqadmin -V /vhost02 -u technix -p PassWord declare queue name=my_queue01
queue declared

To send a message.

$ rabbitmqadmin -V /vhost02 -u technix -p PassWord publish routing_key=my_queue01 payload='Hello RabbitMQ World! My name is technix!' exchange=amq.default
Message published

To receive a message.

$ rabbitmqadmin -V /vhost02 -u technix -p PassWord get queue=my_queue01
| routing_key | exchange | message_count |                  payload                  | payload_bytes | payload_encoding | properties | redelivered |
| my_queue01  |          | 0             | Hello RabbitMQ World! My name is technix! | 41            | string           |            | False       |


From this guide, we have seen how to set up RabbitMQ on CentOS 9|AlmaLinux 9|RHEL 9 systems. We have also seen the benefits of RabbitMQ which include indirectly connecting the published message to a server and then routing it to a consumer (applications that process the message). RabbitMQ is lightweight making it the most deployed message broker on-premises and on the cloud.

Check out more guides on RHEL 9:


Please enter your comment!
Please enter your name here