STOMP adapter updated for RabbitMQ 1.3.0
I’ve updated our STOMP adapter for RabbitMQ to fix a bug reported by Carl Bourne. In the process, I updated the code to work with the latest snapshots of RabbitMQ, including the currently-released version, v1.3.0.
You can get the code by checking it out from our repository with
hg clone http://hg.rabbitmq.com/rabbitmq-stomp/ hg update rabbitmq_v1_3_0_branch
UPDATE: use the default branch these days, unless you’re still running 1.3.0!
or you can instead download a snapshot of the current state of the adapter[1], currently at revision 90dd1726fe0b.
(Update: I forgot to mention that the mercurial repository has two branches in it: default, which tracks our internal RabbitMQ server repository, and rabbitmq_v1_3_0_branch, which should stay compatible with the 1.3.0 server release. Thanks to Aman Gupta, who pointed out the problem in a comment below!)
Here’s a summary of how to build and run a STOMP-enabled RabbitMQ broker – for more details, see the original post on the topic:
- First, retrieve the RabbitMQ server 1.3.0 source code, and unpack it:
- Next, grab the latest STOMP adapter (here we download a copy of the rabbitmq_v1_3_0_branch rather than the main trunk):
- Compile the server itself:
- Finally, compile the adapter, and start the server with extra options that cause the adapter to start too:
If this is successful, you should end up with “starting STOMP-listeners …done” and “broker running” in your terminal. At this point you can try out the service – for instance, you can run Carl’s test cases if you have ruby and rubygems handy:
sudo apt-get install ruby sudo apt-get install rubygems sudo gem install stomp ruby rabbitmq-stomp-rabbitmq_v1_3_0_branch/priv/tests-ruby/cb-receiver.rb
and in another window
ruby rabbitmq-stomp-rabbitmq_v1_3_0_branch/priv/tests-ruby/cb-sender.rb
It will transfer 10,000 short messages, and end up displaying
... Test Message number 9998 Test Message number 9999 All Done!
in the receiver-side terminal.
If you’re interested in the gory details of the bug-fix itself, you can see the relevant patch here. The problem was that the code that handled abrupt socket closure wasn’t handshaking with enough of the internals of the server to ensure that the last few work items were being processed successfully. Trapping socket closure in the STOMP adapter code, and politely handshaking, turned out to be all that was required. An alternative workaround would be to use STOMP’s DISCONNECT method before closing the socket on the client side.
Footnote 1: Note that despite the misleading URL, the snapshot download really is of the STOMP adapter, and not of the broker itself! I’m making use of hgwebdir’s archive-download feature here.

manuel
on 23/05/08 at 9:52 pm
Hello,
I’m trying to run the adapter, but it’s crashing:
<p>Eshell V5.5.5 (abort with ^G)
(rabbit@pennylane)1> {"init terminating in do<em>boot",{undef,[{mnesia,system</em>info,[directory]},{rabbit<em>mnesia,ensure</em>mnesia<em>dir,0},{rabbit,start,0},{init,start</em>it,1},{init,start_em,1}]}}</p>
<p>Crash dump was written to: erl<em>crash.dump
init terminating in do</em>boot ()
make[1]: *** [run] Error 1</p>
<p>
Thank you!
tonyg
on 24/05/08 at 1:09 am
Hi Manuel,
Are you sure you have a full Erlang installation, including Mnesia, available? The error message you’re getting seems to indicate it cannot find the mnesia:system_info function. Some operating systems package the OTP support libraries separately from the core Erlang runtime, so perhaps there is an additional package you could install.
tonyg
on 03/07/08 at 5:40 pm
((I accidentally deleted a bunch of comments I didn’t mean to delete today, so I’m having to repost them manually:))
manuel said:
Hey Tony,
That was it. There was one missing pkg (’erlang’ in Ubuntu Hardy) from my erlang installation. Thanks a lot!!
tonyg
on 03/07/08 at 5:48 pm
((I accidentally deleted a bunch of comments I didn’t mean to delete today, so I’m having to repost them manually:))
Aman Gupta wrote:
Just ran into a bug with the latest hg stomp adapter:
{”init terminating in doboot”,{{nocatch,{error,{cannotstartapplication,rabbit,{badreturn,{{rabbit,start,[normal,[]]},{’EXIT’,{{badmatch,{ok,{0,0,0,0},’rabbitstomplistenersup0.0.0.0:61613′}},[{rabbitstomp,startlisteners,1},{rabbitstomp,start,1},{rabbitstomp,kickstart,0},{rabbit,’-start/2-fun-0-’,1},{lists,foreach,2},{rabbit,start,2},{applicationmaster,startitold,4}]}}}}}}},[{init,startit,1},{init,start_em,1}]}}
Here’s a diff that fixes it:
diff -r 538381ba2feb src/rabbitstomp.erl — a/src/rabbitstomp.erl Mon Jun 16 16:39:29 2008 +0100 +++ b/src/rabbitstomp.erl Wed Jun 25 14:34:13 2008 -0700 @@ -57,7 +57,7 @@ startlisteners([]) -> ok; startlisteners([{Host, Port} | More]) -> - {IPAddress, Name} = rabbitnetworking:checktcplisteneraddress(rabbitstomplistenersup, + {ok, IPAddress, Name} = rabbitnetworking:checktcplisteneraddress(rabbitstomplistenersup, Host, Port), {ok,} = supervisor:start_child(
tonyg
on 03/07/08 at 5:49 pm
((I accidentally deleted a bunch of comments I didn’t mean to delete today, so I’m having to repost them manually:))
tonyg wrote:
Aman, thank you for pointing this out. This is something I should have remarked on in the main article – I’ll update it in a second. The problem is that our internal codebase has moved on a little since RabbitMQ 1.3.0 was released, so there are actually two branches in the rabbitmq-stomp mercurial repository: default, which tracks the main branch of the server, and rabbitmqv130branch, which compiles against the released 1.3.0 release of the server.
The diff you’ve provided catches one of the three areas where the two stomp adapter differ; there are a couple of similar changes that need to be made.
Does it work out-of-the-box if, once you have performed your “hg clone” step, you run “hg update rabbitmqv130branch”, to switch to the maintenance branch, before compiling and running?
jake mallory
on 26/08/08 at 1:57 am
What are the known limitations for the stomp gateway?
tonyg
on 28/08/08 at 12:22 pm
@jake: It implements all the protocol described at http://stomp.codehaus.org/Protocol, hopefully faithfully. There are quite a few AMQP features that are not yet exposed via the STOMP gateway, though; for those, you’ll need to either use a real AMQP client, or send us a patch! (Patches welcome :-) )
jake mallory
on 29/08/08 at 5:49 pm
thanks. I found ruby-ampq (http://github.com/tmm1/amqp/wikis) and qpid (http://cwiki.apache.org/qpid) which I might try instead.
Hans
on 23/11/08 at 10:11 pm
Hi Tony,
I can not find your uploaded file, nor can your mercurial system. Could you upload it again, please? Thanks
tonyg
on 24/11/08 at 12:07 pm
Hi Hans,
Sorry about that — we’ve moved the STOMP adapter to our RabbitMQ hg repository: http://hg.rabbitmq.com/rabbitmq-stomp/
A snapshot can be downloaded from http://hg.rabbitmq.com/rabbitmq-stomp/archive/tip.zip.
sidda
on 08/01/09 at 10:22 pm
Hi Tony,
I ran the rabbitmq-stomp adapter to verify the Stomp client that we have implemented at Kaazing. It works well – thank you.
In the process of running rabbitmq-stomp adapter with RabbitMQ, I noticed that content-length and content-type headers are added stomp frames where required. But, for the ERROR frame the error message is in text and the content-length header set, but the content-type header is not set.
My code, being a generic STOMP client, cannot assume that the content of the ERROR frame is always going to be text – as content-length header is typically used by STOMP servers to send binary data. So, I am writing this comment to find out if you can add content-type header to the ERROR frame in rabbitmq-stomp adapter. I can provide you with the patch required (it is a one line change).
Best Regards, Sidda
tonyg
on 29/01/09 at 3:10 pm
Sidda, that’s a good suggestion. Thanks! I’ve just committed a patch that sets a content-type of text/plain on error messages. The changeset is here: http://hg.rabbitmq.com/rabbitmq-stomp/rev/1a1ff5067bb6
Sig
on 24/03/09 at 5:17 pm
I’m receiving the following with a custom erl built in /usr/local
tonyg
on 25/03/09 at 10:00 am
@Sig: could the problem be that you already have another RabbitMQ instance started? Using “make run” causes a whole broker instance with embedded STOMP adapter to start.
Also, these days, you should probably use the default branch if you can, not the 1.3 support branch; the latest release of RabbitMQ is 1.5.3, and there’s a corresponding STOMP adapter tag. Try this, after ensuring that RabbitMQ is not running:
tonyg
on 25/03/09 at 10:12 am
For those who haven’t yet seen it: the RabbitMQ mailing list is a great place to get help using RabbitMQ, including configuring the STOMP adapter etc. You can subscribe etc via http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss.
Sig
on 26/03/09 at 2:50 am
Thank You!
I finally realized that I had a version running in the background. . I still might join the mailing list, this is a very impressive project.
Cheers