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.
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:
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.
Sudo install wget -y
sudo yum -y install epel-release
sudo yum -y update
wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm ( To download repository)
sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm ( To add repository)
sudo yum -y install erlang socat logrotate (To Install erlang and dependencies)
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)
sudo sh script.rpm.sh
sudo rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc (To add Signing key)
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
sudo yum update -y
sudo systemctl start rabbitmq-server
sudo systemctl enable rabbitmq-server
sudo firewall-cmd –reload
sudo setsebool -P nis_enabled 1
sudo rabbitmq-plugins enable rabbitmq_management
sudo chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/
sudo rabbitmqctl add_user admin password
sudo rabbitmqctl set_user_tags admin administrator
sudo rabbitmqctl set_permissions -p / admin "." "." ".*"
To access the RabbitMQ admin: http://Your_Server_IP:15672