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

  1. Download it
  2. Decompress it and then cd into the directory
  3. ./configure --with-event=/opt/local
  4. make
  5. sudo 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.

Comments

The Web is collaborative. Isn't it great?

Say Your Peace

Textile is allowed. Be polite. Be rude. I don't really give a fuck.

Your email will be kept safe and will never be publicly displayed.

 

Wha...?

11611e595f8866809b075a8e718e7600

Chris Vincent is a 20-something drummer, producer, and engineer from the Bay Area. This is where he writes whatever the hell he wants whenever the hell he wants to write it. Check your expectations at the home page.

Available for hire!

Looking for a top-notch Rubyist for contract? Check my resumé and drop me a line!

Obligatory tag cloud

me san francisco bicycling ruby tdd css tools iphone games rails facebooker queue facebooker facebook arduino activerecord sql css tools development process company culture spam akismet bluepill god

Recent posts

Feed me

Atom is cool.

Get in touch

Questions, comments, ideas?
Let's talk.

Unabashed self-promotion

Recommend Me