rod mclaughlin


Ruby Asynchronous Messaging (05 jul 10)

'Distributed Programming With Ruby' by Mark Bates, Addison Wesley 2010.

DRb - distributed Ruby - Starling - asynchronous message framework

It took me a while to get the examples in the book working

Along with the book, I got a free online version at http://informit.com/safarifree - it doesn't let you copy and paste from it (at least on Firefox 3 under Linux) - so it was no use to me

If you make a mistake in the URL, for example putting a semicolon instead of a colon before the port, you get this helpful error message

/usr/lib64/ruby/gems/1.8/gems/starling-0.10.1/lib/starling.rb:138:in `get_server_for_key': No servers available (all dead) (MemCache::MemCacheError)
from /usr/lib64/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:920:in `request_setup'
from /usr/lib64/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:885:in `with_server'
from /usr/lib64/ruby/gems/1.8/gems/memcache-client-1.8.5/lib/memcache.rb:361:in `set'
        from /usr/lib64/ruby/gems/1.8/gems/starling-0.10.1/lib/starling.rb:69:in `set'
        from simple.rb:10
        from simple.rb:9:in `times'
        from simple.rb:9

and I had some issues getting distributed Ruby to run on more than one machine, however I quickly found two solutions by posting on the Google group for Starling:

http://groups.google.com/group/starlingmq/browse_thread/thread/700a6264eb9096b4

It enables fast reliable simple distributed systems without the overhead of Ruby on Rails if you don't need it:

# client_and_server.rb

require 'rubygems'
require 'starling'

# sudo starling -d _then_ ruby client_and_server.rb runs two processes

URL = 'localhost:22122'
QUE = 'my_queue'

unless fork
  starling = Starling.new URL
  10.times do |i|
        starling.set QUE, i.to_s 
        sleep 0.5
        exit if i == 9
  end
else
  starling = Starling.new URL
  11.times do |i| 
        sleep 0.5
        puts starling.get QUE
        puts `ps auxw | grep client_and_server | grep -v grep` if i == 5
        exit if i == 9
  end
end



Back
Portland London