Baler is a library for managing a pipelined task queue backed by RabbitMQ.
It is the amalgum of two other libraries:
Hopper manages binding to a RabbitMQ queue as a producer and/or consumer.
Hay manages making sense out of tasks and subsequent workflows, and is largely agnostic about how these get moved around.
Baler is the glue that makes RabbitMQ a producer/consumer for Hay style tasks.
Add this line to your application's Gemfile:
gem 'baler'
And then execute:
$ bundle
Or install it yourself as:
$ gem install baler
A system using Baler does so by instantiating {Publisher}s and {Consumer}s.
A Publisher
accepts outbound messages and pass them along a Hay::Route
, and are constructed on demand.
For example, imagine the following Route:
class MyRoute
# A list of tasks that will have Consumers along this route
def self.tasks
[MyTask]
end
# Indicating this is a Route, which must happen *after* the task list
# declaration.
include Hay::Route
end
This is a declaration that MyRoute
is the proper Route for messages to the
Consumer of MyTask
instances.
Detailed documentation on Route
and Task
classes can be found within the Hay
project.
With this route, a {Publisher} can be instantiated as follows:
publisher = Baler::Publisher.new(MockRoute)
Messages can be sent to the Publisher instantiated above by calling
Publisher#publish
with a Hay::Message
instance.
task = MyTask.new(params)
message = Hay::Message.new(my_task)
publisher.publish(message)
Consumers accept inbound messages and act on them. Consumers are typically persistent daemons since messages could arrive on the associated queue at any time.
The following code sets up a Consumer for MyTask
, and sets it listening on
the expected queue.
class MyConsumer
def tasks
[MyTask]
end
include Hay::Consumer
end
consumer = Baler::Consumer.new(MyConsumer)
consumer.listen
See RubyDoc
See Contributing for details.
See TODO for
©2014 Ed Carrel. Released under the MIT License.
See License for details.