Project

lapin

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A sinatra-based app that redirects data received via HTTP to an AMQP message broker.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.9.0.pre7
~> 1.6.1
~> 1.5.2
~> 1.3.5
 Project Readme

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