Project

henchman

0.0
No commit activity in last 3 years
No release in over 3 years
A maximally simple amqp wrapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

henchman

A thin wrapper around amqp.

Installation

Ruby

We use Ruby 1.9.3.

To install and run on your local machine use RVM. For Mac machines make sure you compile with gcc-4.2 (because the compiler from Xcode doesn't compile Ruby 1.9.3 properly). Download and install gcc from https://github.com/kennethreitz/osx-gcc-installer

$ gem install rvm
$ rvm install 1.9.3

And for Macs

$ rvm install 1.9.3 --with-gcc=gcc-4.2

Rubygems

Use Bundler to install the gems needed by Herdis

$ bundle install

RabbitMQ

henchman naturally needs RabbitMQ to run. Install it and run it with default options.

Using

Queues

To enqueue jobs that will only be consumed by a single consumer, you

EM.synchrony do
  Henchman.enqueue("test", {:time => Time.now.to_s})
end

To consume jobs enqueued this way

EM.synchrony do
  Henchman::Worker.new("test") do
    puts message.inspect
    puts headers
  end.consume!
end

The script/enqueue and script/consume scripts provide a test case as simple as possible.

If you want a global error handler for the all consumers in your Ruby environment

EM.synchrony do
  Henchman.error do
    global_error_handler(exception)
  end
end

Broadcasts

To publish jobs that will be consumed by every consumer listening to your exchange, you

EM.synchrony do
  Henchman.publish("testpub", {:time => Time.now.to_s})
end

To consume jobs published this way

EM.synchrony do
  Henchman::Worker.new("test") do
    puts message.inspect
    puts headers
  end.subscribe!
end

The script/publish and script/receive scripts provide a test case as simple as possible.

Error handling is done the exact same way as with the single consumer case.

Test suite

$ rake

Console

To run an eventmachine-friendly console to test your servers from IRB

$ bundle exec em-console