Ruby Findings

digging for gems

Message queues in ruby

Posted by Bill Marquette Thu, 27 Dec 2007 18:59:00 GMT

Sometimes you run across neat and interesting libraries when you are reading up on something completely different. Case in point, via another blog, I stumbled on Reliable Messaging with Ruby. This looks to solve a problem I haven’t yet run into, but I know I’ll find a use for it in the future (maybe for a game I’m slowly working on, or a work project). As of today, there haven’t been any commits to the project for two years, but it’s entirely possible there are no bugs (except for the one I found below) and the author considers it feature complete.

Current feature list:

  • Simple API.
  • Transction processing.
  • Disk-based and MySQL message stores.
  • Best effort, repeated and once-only delivery semantics.
  • Priority queues, message expiration, dead-letter queue.
  • Message selectors.
  • Local and remote queue managers using DRb.

Installation was a breeze

$ sudo gem install reliable-msg -y

For testing, I chose a disk queue, but the library also supports mysql for the message queue.

Note: I used sudo here as my normal user has no access to write the config file - were I to care about this install, I’d spend the time figuring out how to run the queue manager as a non-privileged user.

$ sudo queues install disk foo
Created queues configuration file: /Library/Ruby/Gems/1.8/gems/reliable-msg-1.1.0/queues.cfg

Start up the queue manager:

$ sudo queues manager start
Loaded queues configuration from: /Library/Ruby/Gems/1.8/gems/reliable-msg-1.1.0/queues.cfg
Using message store: disk
Accepting requests at: druby://localhost:6438

I had some issues with drb ACL’s that appear to be due to ACL ordering. After changing line 238 of queue-manager.rb from:

@drb_server = DRb::DRbServer.new drb_uri, self, :tcp_acl=>ACL.new(drb["acl"].split(" "), ACL::ALLOW_DENY)

to:

@drb_server = DRb::DRbServer.new drb_uri, self, :tcp_acl=>ACL.new(drb["acl"].split(" "), ACL::DENY_ALLOW)

I was able to have my test program run. Not sure why I had to make the change, but the queue manager is still denying non localhost connections after it, so I’m not terribly concerned.

$ ruby q.rb
Local: Hello queue master
Queue: Hello queue master

And the contents of q.rb:

require 'rubygems'
require 'reliable-msg'

world = String.new "Hello queue master"
queue = ReliableMsg::Queue.new 'my-queue'
queue.put world
msg = queue.get
puts "Local: #{world}"
puts "Queue: #{msg.object}"

I’m going to let this library permeate my subconscious and find a use for it sometime in the near future.

There is a doc for integrating this library with rails at Reliable Messaging with Rails. Also, AP4R appears to use Reliable Messaging for it’s queueing and looks like a well polished Rails plugin. I don’t have time to look at AP4R now, so I’ll leave a post on that for another day.

Posted in , | 1 comment |