Share on Social Media

Learn step-by-step instructions to install RabbitMQ on Rocky Linux 9 with our comprehensive guide. Set up RabbitMQ effortlessly and optimize your messaging infrastructure today! #centlinux #linux #rabbitmq

What is RabbitMQ?

RabbitMQ is an open-source message broker software that enables applications to communicate and transfer data between each other. It implements the Advanced Message Queuing Protocol (AMQP), which is a widely adopted standard for reliable messaging between different software systems.

At its core, RabbitMQ acts as a mediator or intermediary between two or more applications. It receives messages from a sender, known as a producer, and delivers those messages to a receiver, known as a consumer. The messages are typically organized into queues within RabbitMQ, which provides a way to store and route them.

RabbitMQ supports various messaging patterns, including point-to-point, publish/subscribe, and request/reply. It provides features like message durability, acknowledgments, and routing flexibility, making it a robust and reliable messaging system.

Developers can use RabbitMQ to build distributed and scalable applications that need to handle high volumes of messages and ensure reliable delivery. It is widely used in various industries and scenarios, such as enterprise systems, microservices architectures, event-driven systems, and cloud computing environments.

RabbitMQ is written in Erlang and is known for its stability, performance, and fault-tolerant design. It offers client libraries for multiple programming languages, making it accessible for developers using different technology stacks.

What is RabbitMQ used for?

RabbitMQ is a powerful message broker software that facilitates communication between different applications or services within a distributed system. It acts as a middleman, receiving messages from one application and routing them to another.

Here are some common use cases for RabbitMQ:

  1. Decoupling: RabbitMQ enables decoupling of various components in a system, allowing them to operate independently. This promotes scalability and flexibility in the architecture.
  2. Asynchronous Messaging: It’s often used for asynchronous communication, where a sender doesn’t need an immediate response from the receiver. This is particularly useful in scenarios where processing time varies or when the sender and receiver are not always available simultaneously.
  3. Load Balancing: RabbitMQ can distribute tasks or messages across multiple workers or consumers, balancing the workload efficiently.
  4. Event-Driven Architecture: It’s frequently employed in event-driven architectures, where components react to events triggered by other components. RabbitMQ facilitates the broadcasting of events to interested parties.
  5. Workflow Management: RabbitMQ can be integrated into workflow management systems, ensuring reliable message delivery and processing in complex business processes.
  6. Integration: It’s widely used for integrating disparate systems and applications, allowing them to communicate seamlessly regardless of the underlying technology stack.

Overall, RabbitMQ serves as a reliable, scalable, and flexible messaging solution for various distributed systems and architectures.

RabbitMQ vs Kafka

Here’s a comparison between RabbitMQ and Kafka presented in a table format:

FeatureRabbitMQKafka
Messaging ModelFollows traditional message queue modelDesigned as a distributed streaming platform
Use CasesTraditional messaging scenarios, task distribution, job queues, integrating systemsReal-time event processing, log aggregation, stream processing, event sourcing, data pipeline architectures
ScalabilityVertical scaling by adding resources to a single node, supports clustering for horizontal scalabilityDesigned for horizontal scalability by adding more broker nodes
DurabilityProvides message durability by persisting messages to diskHighly durable by persisting messages to disk and replicating across broker nodes
Message RetentionRetains messages until consumed or expire based on configurable policiesRetains messages for a configurable retention period, allowing replay within that window

This table provides a concise comparison of key features between RabbitMQ and Kafka, making it easier to understand their differences at a glance.

Environment Specification

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 4 GB
  • Storage – 40 GB
  • Operating System – Rocky Linux release 9.2 (Blue Onyx)
  • Hostname – rabbitmq-01.centlinux.com
  • IP Address – 192.168.18.87/24

Prepare your Rocky Linux Server

Login to your Linux server as root user by using a ssh client.

Set a Fully Qualified Domain Name (FQDN) of your Linux machine and set up Local DNS Resolution by executing following commands.

# hostnamectl set-hostname rabbitmq-01.centlinux.com
# echo "192.168.18.87 rabbitmq-01 rabbitmq-01.centlinux.com" >> /etc/hosts

Update software packages in your Linux OS by executing dnf command.

# dnf update -y

If above command installs a new version of Linux Kernel, then you should reboot your Linux OS with new Kernel before installing RabbitMQ software.

# reboot

After reboot, note down the Linux OS and Linux Kernel versions.

# cat /etc/rocky-release
Rocky Linux release 9.2 (Blue Onyx)

# uname -r
5.14.0-284.11.1.el9_2.x86_64

Install Additional Yum Repositories

To install RabbitMQ on Linux, you may need some software packages from Extra Packages for Enterprise Linux (EPEL) yum repository. Therefore, install EPEL yum repository as follows.

# dnf install -y epel-release

You can download RabbitMQ software from their offical website. Or you can install RabbitMQ official yum repository then install Message Broker software by using Linux Package Manager.

We suggest that you should install RabbitMQ on Linux from their official yum repository.

To install RabbitMQ official yum repository, execute following command at Linux terminal.

# curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash

Similarly, you should also install RabbitMQ ErLang repository.

# curl -1sLf 'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/setup.rpm.sh' | sudo -E bash

Build yum cache for newly installed yum repositories.

# dnf makecache
Extra Packages for Enterprise Linux 9 - x86_64  1.7 kB/s | 6.7 kB     00:03
rabbitmq-rabbitmq-erlang                        376  B/s | 659  B     00:01
rabbitmq-rabbitmq-erlang-noarch                 248  B/s | 659  B     00:02
rabbitmq-rabbitmq-erlang-source                 308  B/s | 659  B     00:02
rabbitmq_rabbitmq-server                        794  B/s | 1.8 kB     00:02
rabbitmq_rabbitmq-server-source                 392  B/s | 951  B     00:02
Rocky Linux 9 - BaseOS                          1.8 kB/s | 4.1 kB     00:02
Rocky Linux 9 - AppStream                       2.6 kB/s | 4.5 kB     00:01
Rocky Linux 9 - Extras                          1.9 kB/s | 2.9 kB     00:01
Metadata cache created.

Install RabbitMQ on Rocky Linux 9

All required yum repositories have been added. Now you can install RabbitMQ on Linux by using dnf command.

# dnf install -y rabbitmq-server

Enable and start RabbitMQ service.

# systemctl enable --now rabbitmq-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service → /usr/lib/systemd/system/rabbitmq-server.service.

Install RabbitMQ Plugins

To enable web based Management Console for your Message Broker Software, you need to install RabbitMQ plugins on your Linux Server.

# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@rabbitmq-01:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@rabbitmq-01...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

Configure Linux Firewall:

Identify the service ports, that are being used by RabbitMQ software, execute following commands on Linux terminal.

# ss -tulpn | grep beam
tcp   LISTEN 0      1024                             0.0.0.0:15672      0.0.0.0:*    users:(("beam.smp",pid=2172,fd=37))
tcp   LISTEN 0      128                              0.0.0.0:25672      0.0.0.0:*    users:(("beam.smp",pid=2172,fd=18))
tcp   LISTEN 0      128                                    *:5672             *:*    users:(("beam.smp",pid=2172,fd=35))

# ss -tulpn | grep epmd
tcp   LISTEN 0      4096                             0.0.0.0:4369       0.0.0.0:*    users:(("epmd",pid=2208,fd=3))
tcp   LISTEN 0      4096                                [::]:4369          [::]:*    users:(("epmd",pid=2208,fd=4))

Allow above service ports in Linux firewall.

# firewall-cmd --permanent --add-port={4369,5672,15672,25672}/tcp
success

# firewall-cmd --reload
success

Install rabbitmqadmin on Linux:

The management plugin ships with a command line tool rabbitmqadmin which can perform some of the same actions as the Web-based UI, and which may be more convenient for automation tasks.

rabbitmqadmin can be downloaded from any RabbitMQ node that has the management plugin enabled. Navigate to http://{hostname}:15672/cli/rabbitmqadmin to download it. The tool requires a supported version of Python to be installed.

You can use following curl command to download rabbitmqadmin.

# curl http://localhost:15672/cli/rabbitmqadmin -o /usr/local/bin/rabbitmqadmin
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 42533  100 42533    0     0  2307k      0 --:--:-- --:--:-- --:--:-- 2307k

Grant execute permissions to rabbitmqadmin command.

# chmod +x /usr/local/bin/rabbitmqadmin

Create a RabbitMQ Admin User:

RabbitMQ software shipped with a default user guest with password guest. This guest user has administrative privileges but it can only be login to message-broker server from localhost.

Therefore, you need to create another admin user to access RabbitMQ server web interface remotely.

First, check the already available users on Message Broker server.

# rabbitmqctl list_users
Listing users ...
user    tags
guest   [administrator]

Execute following command at Linux terminal to create a new RabbitMQ user.

# rabbitmqctl add_user admin P@ssw0rd
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.

Set [administrator] tag for admin user to make it a RabbitMQ Administrator.

# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...

Check the list of available users again.

# rabbitmqctl list_users
Listing users ...
user    tags
admin   [administrator]
guest   [administrator]

Create a RabbitMQ Virtual Host:

RabbitMQ is multi-tenant system: connections, exchanges, queues, bindings, user permissions, policies and some other things belong to virtual hosts, logical groups of entities. If you are familiar with virtual hosts in Apache or server blocks in Nginx, the idea is similar. There is, however, one important difference: virtual hosts in Apache are defined in the configuration file; that’s not the case with RabbitMQ: virtual hosts are created and deleted using rabbitmqctl or HTTP API instead.

To create a RabbitMQ virtual host, you can use following Linux command.

# rabbitmqctl add_vhost /my_vhost
Adding vhost "/my_vhost" ...

Check the available virtual host on your Message Broker server.

# rabbitmqctl list_vhosts
Listing vhosts ...
name
/my_vhost
/

Grant permissions on my_vhost to admin user.

# rabbitmqctl set_permissions -p /my_vhost admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/my_vhost" ...

Check the permissions of admin user.

# rabbitmqctl list_user_permissions admin
Listing permissions for user "admin" ...
vhost   configure       write   read
/my_vhost       .*      .*      .*

Check the permission on my_vhost.

# rabbitmqctl list_permissions -p /my_vhost
Listing permissions for vhost "/my_vhost" ...
user    configure       write   read
admin   .*      .*      .*

Create a Message Queue:

You can create a message queue by using rabbitmqadmin command.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd declare queue name=my_queue01
queue declared

Send a message to your message queue by using following command.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd publish routing_key=my_queue01 payload='Hello World!' exchange=amq.default
Message published

Receive the message in your message queue.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd get queue=my_queue01
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count |   payload    | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+
| my_queue01  |          | 0             | Hello World! | 12            | string           |            | False       |
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+

Access RabbitMQ Server Web Interface:

Open URL http://rabbitmq-01.centlinux.com:15672 in a web browser.

RabbitMQ Server Login
RabbitMQ Server Login

Login as admin user.

RabbitMQ Dashboard
RabbitMQ Dashboard

After successful login, you may reach at the dashboard of RabbitMQ Management web interface. You can perform complete administration of your message-broker server from here.

Click on “Queues”.

RabbitMQ Queues
RabbitMQ Queues

Video: RabbitMQ installation on Rocky Linux 9:

YouTube player

Final Thoughts

When delving into the realm of RabbitMQ installation on Rocky Linux 9, meticulous guidance is key. By following our detailed instructions, you’ll seamlessly integrate RabbitMQ into your system, ensuring a robust messaging infrastructure. Let’s embark on this journey together, simplifying the installation process and empowering your system’s capabilities. For more information about using RabbitMQ software, we suggest that you should attend online training RabbitMQ: The Complete Guide with Software Architecture Applicationsudemy-link

Leave a Reply

Your email address will not be published. Required fields are marked *