Installing RabbitMq

This section provides a detailed guide on installing and configuring RabbitMQ.

RabbitMQ, a robust message broker facilitates communication between distributed applications. RabbitMQ is critical for managing asynchronous workflows and ensuring reliable message delivery in a microservices architecture. This page covers setting up RabbitMQ, enabling necessary plugins, creating users, configuring permissions, and customizing settings for seamless integration with your deployment environment.

Prerequisites

Make sure the following things are in place, before installing:

  • Root access to the VM.
  • Redis is installed in the VM.

To install and configure RabbitMQ, follow the steps below:

  1. Run the following bash command to Install necessary utilities for RabbitMQ setup.
    dnf install socat logrotate -y
  2. Download the Erlang package required for RabbitMQ.
    curl -LO -C - https://github.com/rabbitmq/erlang-rpm/releases/download/v26.2.5/erlang-26.2.5-1.el8.x86_64.rpm
  3. Use the following command to install the downloaded Erlang package.
    sudo dnf install ./erlang-26.2.5-1.el8.x86_64.rpm
  4. Run the following script to set up the RabbitMQ package repository.
    curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
  5. Install the RabbitMQ using the package manager.
    dnf install -y rabbitmq-server
  6. Enable the RabbitMQ service to start automatically on boot and then start the service.
    sudo systemctl enable rabbitmq-server
    sudo systemctl start rabbitmq-server
  7. Enable the management plugin to provide a web-based interface for RabbitMQ.
    rabbitmq-plugins enable rabbitmq_management
  8. Now, RabbitMQ is now installed and configured. You can access the RabbitMQ Management UI at http://<server-ip>:15672 using default credentials (guest/guest).

Post Configuration for RabbitMQ

After enabling RabbitMQ and the management plugin, to configure the system further follow these additional steps below:

  1. Navigate to the RabbitMQ configuration directory to add configuration files:
    cd /etc/rabbitmq/
  2. Create the definitions.json file:
    vi definitions.json
  3. Paste the following content into definitions.json to set up a user, permissions, and virtual host:
    {
        "users": [
            {
                "name": "celery",
                "password_hash": "fa604aceeeaae520de8742410200d620edc4a6101fb2971cd706b4cc19141dce",
                "hashing_algorithm": "rabbit_password_hashing_sha256",
                "tags": "administrator"
            }
        ],
        "vhosts": [
            {
                "name": "/"
            }
        ],
        "permissions": [
            {
                "user": "celery",
                "vhost": "/",
                "configure": ".*",
                "write": ".*",
                "read": ".*"
            }
        ],
        "queues": [],
        "exchanges": [],
        "bindings": []
    }
  4. Save and exit the file. Now, update the rabbitmq.conf file:
    vi rabbitmq.conf
  5. Add the following line to load the definitions file during RabbitMQ startup.
    load_definitions = /etc/rabbitmq/definitions.json
  6. Save and exit the file. Now, restart RabbitMQ to apply the changes:
    sudo systemctl stop rabbitmq-server
    sudo systemctl start rabbitmq-server
  7. RabbitMQ is now configured with a predefined user, permissions, and virtual host.