paint-brush
How to Install RabbitMQ On the AWS Ec2 Instanceby@satyapasupuleti
7,011 reads
7,011 reads

How to Install RabbitMQ On the AWS Ec2 Instance

by Satya PasupuletiSeptember 30th, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

RabbitMQ is a message broker that implements an advanced message queueing protocol. Instead of sending messages to the queue, AMQP sends a message to an exchange. Exchange distributes the message to the queues using a concept called Binding. Queue helps in sharing the load and increases performance. RabbitMQ on CentOS 7: EPEL (Extra Packages for Enterprise Linux) is an open-source and free community-based repository. It provides easy access to install packages for commonly used software.

Company Mentioned

Mention Thumbnail
featured image - How to Install RabbitMQ On the AWS Ec2 Instance
Satya Pasupuleti HackerNoon profile picture

In a simple application, a sender sends a message through a TCP protocol, and the receiver receives it. After receiving the message, the receiver needs to send a message back to the sender. If the sender does not receive the message, it tries to connect continuously or send messages to the receiver. If there are many messages to send and the receiver is not responding, the application will crash.


A message queue is created to avoid this problem. A sender can send as many messages as possible, and they move on to their next task. Receiver whenever he is ready he can receive another message. Queue helps in sharing the load and increases performance.


Simple Application

RabbitMQ

RabbitMQ is a message broker that implements an advanced message queueing protocol. Instead of sending a message to the queue, AMQP, it sends a message to an exchange. It acts as a post office. The exchange receives the messages from the sender with a "Routing key". Exchange distributes the message to the queues using a concept called Binding. Exchange is connected to multiple queues. The unique binding key can distinguish each Binding from exchange to queue. Queues are connected to the receiver (You may have one or more receivers).


One great thing about the RabbitMQ model is the flexibility with which the messages can move through the system. Flexibility comes with different exchanges that are available.


For example, fan-out exchange simply ignores the routing key and sends the message to all the available queues.


Direct exchanges send messages to the specific queues where binding key = routing key.


RabbitMQ has one particular exchange default(nameless) exchange. Here the exchanges compare routing key with queue name (not with binding key). When a routing key matches with the queue name, exchanges forward the message to the queue. This helps in the instant sending of a message to the queue.


To sum up:

  1. The sender sends a message to exchange with routing key.
  2. The receiver receives a message from the queue.
  3. Binding connects exchange and queue using the binding key.
  4. Exchange compares routing key with binding key.
  5. The messages distribution way depends on the type of exchange you use.
  6. Different kinds of Exchanges are fan-out direct, nameless, topic header, etc.


The exchange receives the messages from the sender with a "Routing key"

How to do it


Install RabbitMQ on CentOS 7: EPEL (Extra Packages for Enterprise Linux) is an open-source and free community-based repository. It provides easy access to install packages for commonly used software. RabbitMQ is included in standard Fedora and RHEL repositories.



Log in to the instance and switch to root and execute the following commands.


  1. Sudo install wget -y

  2. sudo yum -y install epel-release

  3. sudo yum -y update

  4. wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm ( To download repository)

  5. sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm ( To add repository)

  6. sudo yum -y install erlang socat logrotate (To Install erlang and dependencies)

  7. wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.8/rabbitmq-server-3.8.8-1.el6.noarch.rpm (To download RabbitMQ package)

  8. sudo sh script.rpm.sh

  9. sudo rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc (To add Signing key)

  10. sudo rpm -Uvh rabbitmq-server-3.8.8-1.el6.noarch.rpm or

    wget https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh

  11. sudo yum update -y

  12. sudo systemctl start rabbitmq-server

  13. sudo systemctl enable rabbitmq-server

  14. sudo firewall-cmd –reload

  15. sudo setsebool -P nis_enabled 1

  16. sudo rabbitmq-plugins enable rabbitmq_management

  17. sudo chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/

  18. sudo rabbitmqctl add_user admin password

  19. sudo rabbitmqctl set_user_tags admin administrator

  20. sudo rabbitmqctl set_permissions -p / admin "." "." ".*"


    To access the RabbitMQ admin: http://Your_Server_IP:15672