Installing Beanstalkd on Leopard
May 21, 2009 - 0 Comments - ruby tools
Beanstalkd is a very fast in-memory message queueing service with a nice client gem for Ruby. It has been used to support message queueing for asynchronous processing on the Causes Facebook app, which is written in Ruby on Rails and supports several million users as one of the largest apps on Facebook.
Now that the introduction is out of the way, here’s I installed it on Leopard, since other instructions I found on the web didn’t work for me.
Install libevent
beanstalkd requires libevent. I already had libevent installed. You can find out if you have it installed by running locate libevent in the Terminal. If you don’t have it, get MacPorts if you don’t already have it, then run sudo port install libevent, which should get you up and running.
Install beanstalkd
- Download it
- Decompress it and then
cdinto the directory ./configure --with-event=/opt/localmakesudo mv beanstalkd /usr/local/bin/
Assuming you didn’t get any warnings or errors, you now have beanstalkd on your machine! Run beanstalkd. Some articles claim you’ll get a message like beanstalkd: net.c:90 in unbrake: releasing the brakes, but I got no such thing, just emptiness.
Install the client gem
If you’re going to want to access the beanstalkd queue from Ruby, you will want to install the client gem. It’s easy: sudo gem install beanstalk-client.
Require the gem as necessary (config.gem in Rails, or require 'beanstalk-client' in any other Ruby script.
The easiest way to get at the queue is to set it to a constant, such as BEANSTALK = Beanstalk::Pool.new(['localhost:11300']).
Now you can enqueue a message like this: BEANSTALK.yput(:param => :value). You can retrieve items from the queue (likely from a separate process) with job = BEANSTALK.reserve and then retrieve the body of the message with job.ybody. Make sure that when you’re done with a job that you call job.delete so that beanstalkd can remove it from the queue.
That’s it! Now have fun passing messages around to your disparate Ruby processes. Go build Skynet.
