Tag Archives: RabbitMQ

RabbitMQ admin script based on REST API

Here I use the ruby script below to create a vhost for user, with the corresponding permissions setup. It can delete the vhost and user as well. The script is based on RabbitMQ’s restful admin API.

require "rabbitmq/http/client"
require 'securerandom'

class MQManage

    def initialize(admin_host,mq_host,mq_port,mq_user,mq_pass)
        @mq_host = mq_host
        @mq_port = mq_port
        endpoint = "http://#{admin_host}:15672"
        @client = RabbitMQ::HTTP::Client.new(endpoint, :username => mq_user, :password => mq_pass)

    def create_mq_dsn
        vhost = "/" + SecureRandom.hex(6)
        user = SecureRandom.hex(6)
        pass = SecureRandom.hex(8)
        @client.update_user(user, :tags => "autodeploy", :password => pass)
        @client.update_permissions_of(vhost, user, :write => ".*", :read => ".*", :configure => ".*")

        dsn = {:host => @mq_host, :port => @mq_port, :vhost => vhost, :user => user, :pass => pass}
        return dsn

    def drop_mq_dsn(vhost)
        vs = @client.list_vhosts
        names = []
        vs.each do |s| names << s.name end

        if vhost == "/"
            return -1

        if not names.include? vhost
            return -2

        ps = @client.list_permissions(vhost)
        ps.each do |s|


Install RabbitMQ 3.9 on Ubuntu 16.04

I have an old OS ubuntu 16.04, where I plan to install RabbitMQ 3.9.

Before installing RMQ you should have Erlang installed first. RMQ 3.9 requires the latest version of Erlang 24.

I followed this guide on packagecloud:


It doesn’t work since packagecloud has lost the release source for ubuntu 16.04.

So I google and found this URL:

How to Install Erlang on Ubuntu 18.04 & 16.04 LTS

which does work fine. So the steps I took are:

$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
$ sudo dpkg -i erlang-solutions_1.0_all.deb
$ sudo apt update
$ sudo apt install erlang

After them Erlang 24 was installed successfully on my ubuntu 16.04.

Then we will install the latest RabbitMQ. It is quite easy following packagecloud’s guide:


What I did is:

$ curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash
$ sudo apt update
$ sudo apt install rabbitmq-server

Then RabbitMQ 3.9 was installed successfully on the system (ubuntu 16.04 LTS).

Let’s check the software status:

$ sudo rabbitmqctl status
Status of node [email protected] ...

OS PID: 2729
OS: Linux
Uptime (seconds): 1945
Is under maintenance?: false
RabbitMQ version: 3.9.11
Node name: [email protected]
Erlang configuration: Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]
Erlang processes: 266 used, 1048576 limit
Scheduler run queue: 1
Cluster heartbeat timeout (net_ticktime): 60

As you see it’s Erlang/OTP 24 and RabbitMQ 3.9.11 running there. We have done the good job.

Many factors impact the throughput of RabbitMQ

Many factors impact the throughput you can expect:

  1. Network latency and throughput
  2. Erlang 24 provides 30-40% better performance usually
  3. Disks may be the bottleneck
  4. You need sufficient CPU (at least 2, so that the queue process can use one and there is still at least one more for other processes)
  5. Message size of course (500 bytes is perfectly reasonable size for a message but I believe these tests were using smaller size)
  6. The application itself (you can use https://github.com/rabbitmq/rabbitmq-perf-test which is our go-to testing/benchmarking tool)
  7. And then there is still additional tuning that could be performed (Erlang flags, TCP buffers and many other things)

Also, if you need every last bit of the performance you can get from RabbitMQ then you should probably consider some alternative design choices. Options include:

  1. Using multiple queues
  2. Using sharding or consistent hash exchange
  3. Using a stream instead: https://rabbitmq.com/stream.html