Message queues in ruby
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 -yFor 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.cfgStart 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:6438I 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 masterAnd 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.
Trackbacks
Use the following link to trackback from your own site:
http://www.rubyfindings.com/trackbacks?article_id=message-queues-in-ruby&day=27&month=12&year=2007
about 1 month later: