Here are some notes I have for maintaining RabbitMQ’s AMQP queues using the Erlang shell.

I am using (for demoing purposes) the RabbitMQ installation that came packaged with the On-Demand Elastic Server generated by CohesiveFT. It couldn’t have been any simpler.

To connect to the RabbitMQ Erlang node, you can pull it up through an SSH session into the Elastic Server (ES) itself or you can remotely connect to the Erlang node from your Erlang node. I will describe how to do both.

Connecting to Erlang from within the server:
sudo su - rabbitmq -s /bin/sh -c 'erl -sname foo -remsh rabbit@srabbitmq'

Connecting remotely to the RabbitMQ Erlang node:
There are a few ways to do this. Since this is just for minor maintenance work on my demo, I do not care about security (if I did, I would prefer setting up ~/.erlang.cookie); therefore, I will connect using the node’s cookie in the following manner:
erl -sname foo -setcookie SOMECOOKIE -remsh rabbit@srabbitmq

The cookie (SOMECOOKIE) is obtained by logging into the ES and running:
cat /var/lib/rabbitmq/.erlang.cookie

For connecting remotely from your Windows workstation, use werl instead of erl so that the -remsh option will work.

When connecting remotely, make sure that port 4369 is open on your ES’s firewall and that the port for the current Erlang session is open (an easy way to determine the port on the ES is by reading the firewall error messages in /var/log/messages for the denied port).

Queue Maintenance


%% "At the erlang prompt, type "rabbit_amqqueue:stat_all().", which will
%% produce a brief report on the status of the queues in the system. This
%% tells you how many there are, how many consumers are listening on each,
%% and how many messages are backlogged on each. There is no indication of
%% how many messages have been through the queues yet." - tonyg


%% This example shows one queue, "my_topic_queue", with a single consumer
%% attached without any messages waiting to be consumed.


(rabbit@srabbitmq)1> rabbit_amqqueue:stat_all().
[{ok,{resource,<<"/">>,queue,<<"my_mytopic_queue">>},0,1}]

%% Specify the queue you want, and bind MyTopicQueue to it.

(rabbit@srabbitmq)2> {ok, MyTopicQueue, _, _ } = lists:nth(1, rabbit_amqqueue:stat_all()).
{ok,{resource,<<"/">>,queue,<<"my_mytopic_queue">>},0,1}

%% Lookup the queue and bind it to AMQ. We will purge this queue later.
(rabbit@srabbitmq)3> {ok, AMQ} = rabbit_amqqueue:lookup(MyTopicQueue).
{ok,{amqqueue,{resource,<<"/">>,queue,<<"my_mytopic_queue">>},
    false,
    true,
    [],
    [{binding_spec,{resource,<<"/">>,exchange,<<"my_topic_exch"...>>},
        <<"US.#">>,
        []}],
    <0.317.0>}}

%% Purge the queue
(rabbit@srabbitmq)4> rabbit_amqqueue:purge(AMQ).
{ok,0}

It’s been a while since I took these notes, so things may have changed since then. I just wanted to share my notes with anyone else starting out with RabbitMQ and also to record them on a public medium for when I may need to access them remotely. Please comment with any necessary corrections.

It’s also been a while (2 years) since my last post.

One Response to “RabbitMQ – Basic Queue Maintenance Notes”

  1. alexis said

    Germ, thanks for posting this. Have you been following the discussion on queue management on rabbitmq-discuss? We’d love you to join in. Cheers, alexis

Leave a Reply