How to run RabbitMQ’s experimental STOMP adapter

(This page is a mirrored copy of an article originally posted on the LShift blog; see the archive index here.)

The code for the experimental STOMP adapter for RabbitMQ is distributed separately from the main server, at the moment. This post walks through the steps needed to try the adapter out, running it against a recent snapshot release of RabbitMQ. The perl Net::Stomp STOMP client is used to demonstrate the adapter in action, subscribing to a queue and sending a couple of messages to it.

You will need:

  • Erlang R11B-5 installed, with erl and erlc on your path
  • GNU Make
  • A recent snapshot of RabbitMQ. For this example, I used this one.
  • A recent snapshot of the RabbitMQ STOMP adapter. An up-to-the-minute snapshot is available here (generated on-the-fly from a mercurial repository).

and, optionally, Perl to run the Net::Stomp example (or you could write your own examples using any other STOMP client, of course!); my Mac laptop comes with perl 5.8.8.

The first step is to unpack and compile the RabbitMQ server.

$ tar -zxvf rabbitmq-200801150657.tar.gz
$ cd rabbitmq-200801150657/erlang/rabbit/
$ make
$ cd ../../..

Once that’s done, fetch and extract the latest RabbitMQ STOMP adapter.

$ curl http://hg.rabbitmq.com/rabbitmq-stomp/archive/default.tar.bz2 \
    | tar -jxvf -

Each time a commit is made to the STOMP adapter’s mercurial repository, the hexadecimal revision identifier changes, so the directory created by the unpacking of the snapshot you retrieve will be different. At the time of writing, the STOMP adapter’s directory was rabbitmq-stomp-7b00398dd81f.

To compile the STOMP adapter, you need to point make at the location of the RabbitMQ server codebase you’ve just compiled:

$ cd rabbitmq-stomp-7b00398dd81f/
$ make RABBIT_SOURCE_ROOT=../rabbitmq-200801150657

If you’ve managed to get through all those steps successfully, it’s time to try running the server. Issue the following “make run” command from the rabbitmq-stomp-7b00398dd81f directory:

$ make RABBIT_SOURCE_ROOT=../rabbitmq-200801150657 run
make -C ../rabbitmq-200801150657/erlang/rabbit run \
                RABBIT_ARGS='-pa '"$(pwd)/ebin"' -rabbit \
                        stomp_listeners [{\"0.0.0.0\",61613}] \
                        extra_startup_steps [{\"STOMP-listeners\",rabbit_stomp,kickstart,[]}]’
NODE_IP_ADDRESS= NODE_PORT= NODE_ONLY=true LOG_BASE=/tmp  RABBIT_ARGS=”-pa /Users/tonyg/dev/AMQ/scratch/rabbitmq-stomp-7b00398dd81f/ebin -rabbit                stomp_listeners [{\"0.0.0.0\",61613}]           extra_startup_steps [{\"STOMP-listeners\",rabbit_stomp,kickstart,[]}] -s rabbit” MNESIA_DIR=/tmp/rabbitmq-rabbit-mnesia ./scripts/rabbitmq-server
Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:30] [kernel-poll:true]

Eshell V5.5.5  (abort with ^G)
(rabbit@walk)1> RabbitMQ 200801150657 (AMQP 8-0)
Copyright (C) 2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
Licensed under the MPL.  See http://www.rabbitmq.com/

Logging to “/tmp/rabbit.log”
SASL logging to “/tmp/rabbit-sasl.log”

starting database             …done
starting core processes       …done
starting recovery             …done
starting persister            …done
starting builtin applications …done
starting TCP listeners        …done
starting STOMP-listeners      …done

broker running

Now, let’s try it out. I’ll use the Perl Net::Stomp module, available on CPAN.

$ sudo cpan -i Net::Stomp

The examples I’m going to try out are those from the Net::Stomp documentation - run perldoc Net::Stomp to read the originals. Save the following code into rabbit_stomp_send.pl:

# send a message to the queue 'foo'
use Net::Stomp;
my $stomp = Net::Stomp->new({hostname=>'localhost', port=>'61613'});
$stomp->connect({login=>'guest', passcode=>'guest'});
$stomp->send({destination=>'foo', body=>($ARGV[0] or ‘test message’)});
$stomp->disconnect;

and the following code into rabbitmq_stomp_recv.pl:

# subscribe to messages from the queue 'foo'
use Net::Stomp;
my $stomp = Net::Stomp->new({hostname=>'localhost', port=>'61613'});
$stomp->connect({login=>'guest', passcode=>'guest'});
$stomp->subscribe({'destination'=>'foo', 'ack'=>'client'});
while (1) {
    my $frame = $stomp->receive_frame;
    print $frame->body . "\n";
    $stomp->ack({frame=>$frame});
    last if $frame->body eq 'QUIT';
}
$stomp->disconnect;

Run the receiver before the sender to make sure the queue exists at the moment the send takes place. In one terminal window, start the receiver:

$ perl ./rabbitmq_stomp_recv.pl

In another terminal window, run the sender:

$ perl ./rabbitmq_stomp_send.pl
$ perl ./rabbitmq_stomp_send.pl "hello world"
$ perl ./rabbitmq_stomp_send.pl QUIT

The receiver’s window should contain the received messages:

$ perl ./rabbitmq_stomp_recv.pl 
test message
hello
QUIT
$

Comments

On 3 April, 2008 at 12:30 am, Carl Bourne wrote:

Does this currently support SSL/TLS?

On 15 April, 2008 at 2:26 am, Henry Kaufman wrote:

Hi,
I’m interested in trying out the rabbitmq-stomp server to provide server support for a Flash-based chat client that I am working on, but I’m having trouble getting started.

I tried to follow your step-by-step instructions on WindowsXP, but came across several stumbling blocks. The version of rabbitmq-stomp that is currently available (rabbitmq-stomp-b01c04778288) does not seem to be compatible with the rabbitmq server any more. When the “make … run” command is issued (under cygwin bash or the dos shell), I get shell syntax errors:
$ make RABBITSOURCEROOT=../rabbitmq-200801150657 run
c:/Program Files/GNU/make -C ../rabbitmq-200801150657/erlang/rabbit run \
RABBITARGS=’-pa ‘”$(pwd)/ebin”‘ -rabbit \
stomp
listeners [{\"0.0.0.0\",61613}] \
extrastartupsteps [{\"STOMP-listeners\",rabbitstomp,kickstart,[]}]’
/usr/bin/sh: -c: line 1: syntax error near unexpected token ('
/usr/bin/sh: -c: line 1:
RABBIT
ARGS=’-pa ‘\$(pwd)/ebin\’ -rabbit \’
make: *** [start_server] Error 2

What shell should I use to execute ‘make … run’ in?

If I manually create that run command, I get runtime errors too:
$ cd ../rabbitmq-200801150657/erlang/rabbit
$ make run RABBITARGS=’-pa ./ebin -rabbit \
stomp
listeners [{\"0.0.0.0\",61613}] \
extrastartupsteps [{\"STOMP-listeners\",rabbit_stomp,kickstart,[]}]’

output:
NODEIPADDRESS= NODEPORT= NODEONLY=true LOGBASE=/tmp RABBITARGS=”-pa ./ebin -rabbit \
stomplisteners [{\"0.0.0.0\",61613}] \
extra
startupsteps [{\"STOMP-listeners\",rabbitstomp,kickstart,[]}] -s rabbit” MNESIADIR=/tmp/rabbitmq-rabbit-mnesia ./scripts/rabbitmq-server
kernel-poll not supported; “K” parameter ignored
Eshell V5.5.5 (abort with ^G)
(rabbit@henry-mac)1> {”init terminating in do
boot”,{{nocatch,{error,{cannotlogtofile,”/tmp/rabbit.log”,eexist}}},[{init,startit,1},{init,start_em,1}]}}

Crash dump was written to: erlcrash.dump
init terminating in do
boot ()
make: *** [run] Error 1

Any ideas why trying to run the rabbitmq server with Stomp is crashing? Any help would be much appreciated!
Thanks,
-Henry

On 18 April, 2008 at 4:43 pm, tonyg wrote:

@Carl: Not explicitly. You could, of course, turn on SSL in whatever client library you use and use stunnel4 on the server-side to wrap the STOMP adapter.

On 18 April, 2008 at 4:46 pm, tonyg wrote:

@Henry: Sorry about that. The STOMP adapter isn’t presently an official part of RabbitMQ, and I’ve not had an opportunity to update it to work with RabbitMQ 1.3. It should work with the specific snapshots mentioned in the post.

The shell I usually use is bash. With regard to the crash-on-manual run, it looks like it’s failing to be able to write to /tmp. If you’re using cygwin, chances are this is because of a disconnect between the Unix mode and the Windows mode of the system. Try setting LOG_BASE to something other than /tmp.

On 28 April, 2008 at 12:03 am, Carl Bourne wrote:

Hi I’ve been doing some testing with the rabbitmq-200803291005 snapshot and the Ruby Stomp library.

I have test sender:

require ‘rubygems’
require ’stomp’

client = Stomp::Client.new(”guest”, “guest”, “192.168.1.17″, 61613)
10000.times { |i| client.send ‘carl’, “Test Message number #{i}”}
client.send ‘carl’, “All Done!”

A test receiver:

require ‘rubygems’
require ’stomp’

conn = Stomp::Connection.open(’guest’, ‘guest’, ‘192.168.1.17′)
conn.subscribe(’carl’)
while true
mesg = conn.receive

puts mesg if mesg

puts mesg.body if mesg
sleep 0.0001
end

However it seems that every third batch of 10000 messages I send, the receiver (or maybe its the sender) drops the last 10-20 messages. I’ve tested this on Ubuntu and MAC OSX.

Any Idea what could cause this?

Also, when will the stomp adapter be included in the official RabbitMQ distribution? or better still will there be a native AMQP library for Ruby?

Best Regards,

Carl

On 29 April, 2008 at 6:20 pm, tonyg wrote:

Carl, thank you for your comment - you have discovered a bug in the STOMP adapter. I’ll update here and on the mailing-list when we have a fix. Regards, Tony

On 7 August, 2008 at 7:59 pm, tonyg wrote:

On 12 February, 2009 at 7:33 pm, Ronen wrote:

I’m using the STOMP adapter for RabbitMQ (v1.5.1) and the Python module stomp.py. It connects fine, but as soon as I try to
subscribe or send a message I get an error message.

$ ./rabbitmq-server
RabbitMQ 1.5.1 (AMQP 8-0)
:
starting TCP listeners ...done
starting STOMP-listeners ...done

broker running

As soon as I run the simple example at the top of this post I get:

received an error {undef,[{rabbitchannel,startlink,
[rabbitstomp,<0.160.0>,<0.160.0>,<<"guest">>,
<<"/">>]},
{rabbit
stomp,dologin,4},
{rabbit
stomp,processframe,3},
{rabbit
stomp,processreceivedbytes,2},
{rabbitstomp,init,1},
{proc
lib,initpdo_apply,3}]}

The corresponding log lines are:

=INFO REPORT==== 12-Feb-2009::09:58:42 ===
starting STOMP connection <0.160.0> from 127.0.0.1:60233

=ERROR REPORT==== 12-Feb-2009::09:58:42 ===
STOMP error frame sent:
Message: “Processing error”
Detail: “{undef,[{rabbitchannel,startlink,\n [rabbitstomp,<0.160.0>,<0.160.0>,<<\"guest\">>,\n <<\"/\">>]},\n {rabbitstomp,dologin,4},\n {rabbitstomp,processframe,3},\n {rabbitstomp,processreceivedbytes,2},\n {rabbitstomp,init,1},\n {proclib,initpdo_apply,3}]}\n”

=INFO REPORT==== 12-Feb-2009::09:58:42 ===
ending STOMP connection <0.160.0> from 127.0.0.1:60233

Does anybody have an idea what’s wrong here? AMQP connections to this same
server work just fine.

On 13 February, 2009 at 2:08 am, tonyg wrote:

Hi Ronen, you will need to use tag rabbitmq_v1_5_1 of the STOMP adapter with the 1.5.1 broker:

(cd rabbitmq-stomp; hg up rabbitmq_v1_5_1; make)

The internal APIs for channel setup changed between 1.5.1 and the tip-of-default.

On 19 February, 2009 at 11:42 am, Sanjay wrote:

I am getting this error when I start the perl receive script - rabbitmqstomprecv.pl

Error reading command: at /usr/lib/perl5/site_perl/5.8.5/Net/Stomp/Frame.pm line 37, line 5.

On 19 February, 2009 at 7:55 pm, tonyg wrote:

Hi Sanjay, sorry to hear you’re having problems. The script works for me; I think I’ll need more to go on if I’m to help you. Please join the rabbitmq mailing list — see http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss — and ask your question again there.

On 16 April, 2009 at 7:43 pm, nemanja wrote:

Sanjay,

I had the same error. Resolved it by using the tip versions from mercurial of both the rabbitmq-server and the STOMP adapter. Worked just fine after that.

On 18 April, 2009 at 2:48 am, tonyg wrote:

(@nemanja, @Sanjay: Specifically, use the default branch of both the server and STOMP adapter:

hg clone http://hg.rabbitmq.com/rabbitmq-server
hg clone http://hg.rabbitmq.com/rabbitmq-codegen
hg clone http://hg.rabbitmq.com/rabbitmq-stomp
make -C rabbitmq-server
make -C rabbitmq-stomp run

)

On 26 February, 2010 at 7:46 pm, jesse wrote:

I grabbed the latest server source and built it then cloned the stomp repository as a subdirectory of the server source directory.

When I to try to make the stomp adapter with the command:
make RABBITSOURCEROOT=../

Has anyone ran into this or have any idea what I am doing wrong?

On 20 October, 2010 at 8:23 am, RabbitMQ OpenSources Messages Service « TuXxX Blog wrote:

[...] Stomp [...]