0.01
No commit activity in last 3 years
No release in over 3 years
QueueingRabbit is a Ruby library providing a flexible DSL to interact with a RabbitMQ server. Any Ruby class or Module can be transformed into QueueingRabbit's background job by including QueueingRabbit::Job module. It is also possible to inherit your class from QueueingRabbit::AbstractJob abstract class. The library is bundled with a Rake task to start a worker processing a list of specified jobs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.3.0
~> 1.9.0
~> 1.6.3
>= 0
>= 0
 Project Readme

QueueingRabbit Build Status Code Climate

QueueingRabbit provides a Ruby DSL to interact with RabbitMQ. It is fairly flexible and allows you to integrate with existing infrastructure and naming conventions. It currently offers gems bunny and amqp as supported back-ends.

Disclaimer

I built this gem at Wildbit in 2012. Back then there weren’t any solid generic queueing systems targeting RabbitMQ for Ruby. The gem was open-sourced in early 2013, but I never put any effort into selling it to the community. Even though the gem is working, maintained, and is still used by Wildbit in production, in the long run you should be better with now-existing mainstream alternatives like hutch and sneakers.

Example

The following Ruby program publishes an excerpt of Joseph Brodsky’s poem line by line to a RabbitMQ exchange and prints received messages on the screen.

require 'queueing_rabbit'

class Reciter < QueueingRabbit::AbstractJob

  def perform
    puts payload
  end

end

worker = QueueingRabbit::Worker.new(Reciter)

poem = <<-
  I said fate plays a game without a score,
  and who needs fish if you've got caviar?
  The triumph of the Gothic style would come to pass
  and turn you on - no need for coke, or grass.
  I sit by the window. Outside, an aspen.
  When I loved, I loved deeply. It wasn't often.


Thread.new {
  poem.each_line { |l| Reciter.enqueue(l) }
  sleep 5
  worker.stop
}

worker.work!

This code has following important side effects:

  • A Rabbit queue named Reciter is created with default options (if not exists).
  • 6 messages are published to the default exchange with routing key Reciter.
  • 6 messages are consumed from the Reciter queue.
  • 6 lines of the poem are printed to STDOUT.

Choosing the back-end: bunny or amqp?

Bunny is a pseudo-synchronous RabbitMQ client. Amqp is EventMachine-based and heavily asynchronous (lots of callbacks involved). Both clients are in active development, thoroughly documented and fairly stable.

Choose bunny if you don’t want to worry about blocking I/O and EventMachine-compilant drivers. Choose amqp if you’re familiar with EventMachine, designing a lightweight app from scratch and performance is a serious concern. Obviously there are exceptions, and no one knows your requirements better than you.

Also, you can use both of them. For example, you may decide to publish via bunny from your Rails app and use amqp in your background worker.

Documentation & Support

Check out the project wiki for additional guidance. If you have questions or something doesn’t work for you, feel free to file issues.

Installation

QueueingRabbit supports MRI Ruby version 1.9.3 and above. It is still compilant with Ruby 1.8.7, but some features may not work as expected and the compatibility will be removed in the near future.

Add this line to your application's Gemfile:

gem 'queueing_rabbit'

And then execute:

$ bundle

Or install it globally as:

$ gem install queueing_rabbit

Special Thanks

  • Wildbit — for letting me open source this library initially developed for the internal use.
  • RabbitMQ client libraries for Ruby — for providing outstanding well-documented gems that made this project possible.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request