/lapin

A sinatra-based app that redirects data received via HTTP to an AMPQ message broker.

Primary LanguageRuby

Lapin

Build Status Code Climate

A sinatra-based app that provides a JSON endpoint over HTTP for interacting with an AMQP message broker.

Requirements

Installation

$ gem install lapin

To use with bundler, drop in your Gemfile.

gem "lapin", :git => "git://github.com/giraffi/lapin.git"

Setup

Create config.ru in the root folder of your app.

require 'lapin'

Lapin::Config.amqp_url = 'amqp://guest:guest@localhost/vhost'
Lapin::Config.exchange = 'amq.direct'
Lapin::Config.logging  = true if ENV['RACK_ENV'] == 'development'
Lapin.options.quiet    = false

run Lapin::Server

Usage

Just do the following to start Lapin::Server using thin for the web server.

$ thin start -R config.ru

Or, rackup with puma,

$ rackup config.ru -s puma

To handle a POST request like below, you need a running RabbitMQ server according to the Lapin::Config.amqp_url option beforehand.

$ curl -v \
> -H "Accept: application/json" -H "Content-type: application/json" -H "X-ROUTING-KEY: amqp.giraffi" \
> -X POST -d '{"user":{"name":"foo", "email":"hoge@example.com"}}'  \
> http://localhost:3000/publish.json