0.0
A long-lived project that still receives updates
Simply and easily add AMQP messaging capabilities to your services
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

 Project Readme

CottonTail

CircleCI Depfu Code Climate

CottonTail lets you declare RabbitMQ queues and routing-key patterns as elegantly as you declare HTTP routes in a web framework, processes messages through a familiar middleware pipeline, and keeps all the AMQP/Bunny plumbing out of sight.

Installation

Add this line to your application's Gemfile:

gem 'cotton-tail'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cotton-tail

Usage

Quick Start (Hello World)

require 'bundler/setup'
require 'cotton_tail'

app = CottonTail::App.new

app.routes.draw do
  # Create the queue 'hello_world' if it does not exists
  queue 'hello_world', exclusive: true do
    # Create a binding from the default topic exchange ('amq.topic') to
    # the queue 'hello_world'. When a message is received with the
    # routing key 'say.hello' the block is executed.
    handle 'say.hello' do
      puts 'Hello world!'
    end
  end
end

app.start

To run the example locally you need to have a rabbitmq instance running. The included docker-compose file can be used to start up a local instance of rabbitmq.

docker-compose up

Once the rabbitmq service has completed startup (takes a few seconds) you can start the example app.

bundle exec examples/app.rb

You should see

Waiting for messages ...

We've included bash scripts to publish messages for the example app. Execute them in another terminal window to see output in the app window.

# you might need to chmod +x these scripts first
./examples/messages/say.hello

Development

After checking out the repo, install docker. Then, run docker-compose up to spin up a local instance of rabbitmq. Run rake spec:all to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jamesBrennan/cotton-tail.