Introduction to RabbitMQ

RabbitMQ is an open source message broker. It acts as a middleware for sending and receiving messages between different components in an application.

Introduction

RabbitMQ implements AMQP. It helps to scale applications by decoupling dependency between two components in an application. Application components are decoupled by moving to asynchronous message-based communication.

Installation on CentOS 6.9

Install and enable EPEL repository

1
2
sudo yum -y install epel-release
sudo yum repolist

Install erlang (zero-dependency Erlang from RabbitMQ)

1
2
3
cd /usr/local/src
sudo wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el6.x86_64.rpm
sudo yum -y install erlang-19.0.4-1.el6.x86_64.rpm

RabbitMQ installation

1
2
3
4
5
6
cd /usr/local/src
sudo wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5-1.noarch.rpm 
sudo rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
sudo yum -y install rabbitmq-server-3.6.5-1.noarch.rpm

sudo service rabbitmq-server status

Managing RabbitMQ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Running RabbitMQ Server
sudo service rabbitmq-server start/stop/status

# Managing the Broker
sudo rabbitmqctl status/stop

# Start server on system boot
sudo chkconfig rabbitmq-server on

# Logging
/var/log/rabbitmq

Enabling management plugin (on https)

1
2
3
4
5
6
7
8
9
sudo rabbitmq-plugins enable rabbitmq_management

sudo mkdir -p /etc/rabbitmq/ssl/
cd /etc/rabbitmq/ssl/

# for development server, use below command to create self signed certificate
# answer all the questions with dummy data while generating key

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/rabbitmq/ssl/ca.key -out /etc/rabbitmq/ssl/ca.crt
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sudo vim /etc/rabbitmq/rabbitmq.config
[{rabbitmq_management,
  [{listener, [{port,     15672},
               {ssl,      true},
               {ssl_opts, [{cacertfile, "/etc/rabbitmq/ssl/ca.crt"},
                           {certfile,   "/etc/rabbitmq/ssl/ca.crt"},
                           {keyfile,    "/etc/rabbitmq/ssl/ca.key"}]}
              ]}
  ]}
].
1
2
sudo rabbitmqctl stop
sudo service rabbitmq-server start
1
2
3
4
5
# default guest account by default works on localhost only. If you want 
# to access management console URL outside the server, create a different account (mentioned in next step)
# guest account should be deleted

https://localhost:15672/ (guest/guest)

Adding new admin

1
2
3
4
5
sudo rabbitmqctl add_user newadmin password
sudo rabbitmqctl set_user_tags newadmin administrator
sudo rabbitmqctl set_permissions -p / newadmin ".*" ".*" ".*"

https://server-name:15672/ (newadmin/password)

Deleting guest user

1
2
https://server-name:15672/ (newadmin/password)
Home > Admin

RabbitMQ docker instance

Downloading RabbitMQ docker image

1
docker pull rabbitmq:3.6.12

Running a rabbitmq container

1
2
3
docker run -d --hostname local-rabbitmq --name rabbitmq-15672 -p 15672:15672 rabbitmq:3.6.12

docker logs rabbitmq-15672

RabbitMQ docker instance with management plugin

1
2
3
4
5
6
7
8
# downloading docker image
docker pull rabbitmq:3.6.12-management

# running container
docker run -d --hostname local-rabbitmq --name rabbitmq-15672 -p 15672:15672 -p 5672:5672 rabbitmq:3.6.12-management

# access http://localhost:15672/ (guest/guest)
# for AMQP connections use localhost:5672 (guest/guest)