Producer/Consumer using beanstalkd in Ruby
Got basic queueing to work in ruby using beanstalkd/beanstalk-client.
Producer.rb
#!/usr/bin/env ruby require 'rubygems' require 'beanstalk-client' beanstalk = Beanstalk::Pool.new(['localhost:11300']) while(true) do sleep(10) puts "posting message ..." beanstalk.put(Time.now.to_s) end
Consumer.rb
#!/usr/bin/env ruby require 'rubygems' require 'beanstalk-client' beanstalk = Beanstalk::Pool.new(['localhost:11300']) loop do job = beanstalk.reserve puts job.body job.delete end
Commands:
$ beanstalkd -d -p 11300 $ ./producer.rb # consumer in a different terminal $ ./consumer.rb
Enjoy!
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.






Have a look at AMQP if you need persistent queues…
http://github.com/tmm1/amqp/tree/master
RabbitMQ is also pretty nice for a server as it is written in Erlang.
Ray Krueger
21 Jul 09 at 9:44 pm
Thanks Ray, wasn’t aware of this. We are migrating away from ActiveMQ, ’cause it is too heavy weight. In my mind, beanstalkd is lean. AMQP seems similar and flexible incase if we need advanced features (persistence) in future.
Will take a look. Thanks again.
Sharad
23 Jul 09 at 1:03 am