Ruby + AMQP + RabbitMQ Example
24 Jun 2008
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.
Comments (5)
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
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).
right on. I had both, but was using the wrong one.
Have you played with the ruby ampq client on github? Any Thoughts?
No, haven't had a chance to play with it yet, but I am hearing it's very good.
instead of... def open_or_nil(filename) begin File.open(filename) rescue nil end end ...you can simple write... File.open(filename) rescue nil