Lapine
Speak to RabbitMQ. This gem serves as a wrapper for publishing messages to RabbitMQ via the Bunny gem.
Configuration
Initialization can be done inline in a daemon, or if used in Rails
an initializer should be made at config/initializers/lapine.rb
Register a connection. This connection should be given a name, and a hash of connection options that will be passed through to Bunny.
Lapine.add_connection 'my-connection', {
host: 'my-rabbitmq.mine.com',
port: 5672,
user: 'rabbit',
password: 'meow'
}
Then register an exchange.
Lapine.add_exchange 'efrafa',
durable: true,
connection: 'my-connection', # required
type: 'topic' # required
Usage
Define a class that configures which exchange is uses. This class
must define #to_hash
require 'lapine'
class Worker
include Lapine::Publisher
exchange 'efrafa'
def initialize(action)
@action = action
end
def to_hash
{
'action' => @action
}
end
end
This class can be used to publish messages onto its exchange:
Worker.new('dig').publish
Publishing can take a routing key for topic exchanges:
Worker.new('dig').publish('rabbits.drones')
Note that the #initialize method and the contents of #to_hash
are arbitrary.
But... WHY
- This should be dead simple, but everything else was either too complex or assumed very specific configurations different from what we want.
Contributing
- Fork it ( https://github.com/[my-github-username]/lapine/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request