Tackle
Tackles the problem of processing asynchronous jobs in reliable manner by relying on RabbitMQ.
Installation
Add this line to your application's Gemfile:
gem "rt-tackle", :require => "tackle"
Usage
Publishing a message
With tackle, you can publish a message to an AMQP exchange. For example, to
publish "Hello World!" do the following:
= {
:url => "amqp://localhost",
:exchange => "test-exchange",
:routing_key => "test-messages",
}
Tackle.publish("Hello World!", )
Optionally, you can pass a dedicated logger to the publish method. This comes handy if you want to log the status of your publish action to a file.
= {
:url => "amqp://localhost",
:exchange => "test-exchange",
:routing_key => "test-messages",
:logger => Logger.new("publish.log")
}
Tackle.publish("Hello World!", )
Consume messages
Tackle enables you to connect to an AMQP exchange and consume messages from it.
require "tackle"
= {
:url => "amqp://localhost",
:exchange => "users",
:routing_key => "signed-up",
:service => "user-mailer",
:exception_handler => lambda { |ex, consumer| puts ex. }
}
Tackle.consume() do ||
puts
end
The above code snippet creates the following AMQP resources:
- A dedicated exchange for your service, in this example
user-mailer.signed-up - Connects your dedicated
user-mailer.signed-upexchange to the remote exchange from which you want to consume messages, in this exampleusersexchange - Creates an AMQP queue
user-mailer.signed-upand connects it to your local exchange - Creates a delay queue
user-mailer.signed-up.delay. If your service raises an exception while processing an incoming message, tackle will put it in this this queue, wait for a while, and then republish to theuser-mailer.signed-upexchange. - Creates a dead queue
user-mailer.signed-up.dead. After several retries where your service can't consume the message, tackle will store them in a dedicated dead queue. You can consume this messages manually.

You can pass additional configuration to tackle in order to control the number of retries, and the delay between each retry.
require "tackle"
options = {
:url => "amqp://localhost",
:exchange => "users",
:routing_key => "signed-up"
:service => "user-mailer",
:retry_limit => 8,
:retry_delay => 30,
:exception_handler => lambda { |ex, consumer| puts ex.message }
}
Tackle.consume(options) do |message|
puts message
end
By default, tackle logs helpful information to the STDOUT. To redirect these
messages to a file, pass a dedicated logger to tackle.
require "tackle"
options = {
:url => "amqp://localhost",
:exchange => "users",
:routing_key => "signed-up"
:service => "user-mailer",
:retry_limit => 8,
:retry_delay => 30,
:logger => Logger.new("consumer.log"),
:exception_handler => lambda { |ex, consumer| puts ex.message }
}
Tackle.consume(options) do |message|
puts message
end
Development
After checking out the repo, run bin/setup to install dependencies. Then,
run rake rspec to run the tests. You can also run bin/console for an
interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
To release a new version, update the version number in version.rb, and
then run bundle exec rake release, which will create a git tag for the
version, push git commits and tags, and push the .gem file
to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/renderedtext/tackle.