Ruby + AMQP + RabbitMQ Example

In this post I would like to show how one can exchange messages using AMQP protocol from Ruby, using RabbitMQ as a broker. I posted the original version of this script to rabbitmq-discuss mailing list back in September 2007.

Prerequesites:

  • RabbitMQ broker configured, up and running on 127.0.0.1 (localhost) on port 5672 (standard AMQP port).
  • Apache QPid Ruby library installed within RUBYPATH (svn co http://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/ruby)
  • AMQP specification XML form AMQP official site saved as /etc/amqp0-8.xml

You can also download this script from here.

Categories: rabbitmq | ruby |

Comments (5)

tinomen // 05 Sep 2008

Should the producer be tailing to the console? I'm getting the following error:

./disttailf.rb -x /usr/local/qpid/specs/amqp.0-8.xml -s 127.0.0.1 -p 5672 -c CONNECTION CLOSED: 501, FRAME_ERROR - cannot decode <>, 60, 20 writer Qpid::Closed /usr/local/qpid/ruby/qpid/queue.rb:41:in `pop': Qpid::Closed (Qpid::Closed) from /usr/local/qpid/ruby/qpid/peer.rb:208:in `invoke' from /usr/local/qpid/ruby/qpid/peer.rb:190:in `method_missing' from ./disttailf.rb:25:in `consumer' from ./disttailf.rb:126

Dmitriy // 06 Sep 2008

It looks to me like you are using the spec XML which came with QPid. Please download the official spec XML form amqp.org (see the link in my post above).

tinomen // 09 Sep 2008

right on. I had both, but was using the wrong one.

Have you played with the ruby ampq client on github? Any Thoughts?

Dmitriy // 09 Sep 2008

No, haven't had a chance to play with it yet, but I am hearing it's very good.

darxriggs // 22 Apr 2009

instead of... def open_or_nil(filename) begin File.open(filename) rescue nil end end ...you can simple write... File.open(filename) rescue nil