Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 603159eded4dd08f898fad9500d634d46f5a0397 Glenn Gillen committed Aug 29, 2011
Showing with 112 additions and 0 deletions.
  1. +6 −0 Gemfile
  2. +27 −0 Gemfile.lock
  3. +1 −0 Procfile
  4. +26 −0 app.rb
  5. +3 −0 config.ru
  6. +24 −0 lib/sinatra_rabbitmq.rb
  7. +19 −0 views/index.haml
  8. +6 −0 views/layout.haml
@@ -0,0 +1,6 @@
+source :rubygems
+gem 'sinatra'
+gem 'thin'
+gem 'bunny'
+gem 'json'
+gem 'haml'
@@ -0,0 +1,27 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ bunny (0.7.4)
+ daemons (1.1.4)
+ eventmachine (0.12.10)
+ haml (3.1.2)
+ json (1.5.3)
+ rack (1.3.2)
+ sinatra (1.2.6)
+ rack (~> 1.1)
+ tilt (< 2.0, >= 1.2.2)
+ thin (1.2.11)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bunny
+ haml
+ json
+ sinatra
+ thin
@@ -0,0 +1 @@
+web: bundle exec thin start -p $PORT
26 app.rb
@@ -0,0 +1,26 @@
+require 'sinatra/base'
+require 'lib/sinatra_rabbitmq'
+
+class RabbitmqDemo < Sinatra::Base
+ register Sinatra::RabbitMQ
+
+ get "/" do
+ haml :index
+ end
+
+ post "/" do
+ self.class.rabbitmq_exchange.publish params["message"], :key => "messages"
+ @notice = "Message has been published."
+ haml :index
+ end
+
+ get "/message" do
+ msg = self.class.rabbitmq_messages_queue.pop
+ if msg[:payload] == :queue_empty
+ @notice = "No more messages."
+ else
+ @message = msg[:payload]
+ end
+ haml :index
+ end
+end
@@ -0,0 +1,3 @@
+require 'app'
+run RabbitmqDemo
+
@@ -0,0 +1,24 @@
+require 'sinatra/base'
+require 'bunny'
+
+module Sinatra
+ module RabbitMQ
+ def rabbitmq_client
+ return @rabbitmq_client if @rabbitmq_client
+ @rabbitmq_client = Bunny.new(ENV["RABBITMQ_URL"])
+ @rabbitmq_client.start
+ @rabbitmq_client
+ end
+
+ def rabbitmq_exchange
+ @rabbitmq_exchange ||= rabbitmq_client.exchange("")
+ end
+
+ def rabbitmq_messages_queue
+ @rabbitmq_messages_queue ||= rabbitmq_client.queue("messages")
+ end
+ end
+
+ register RabbitMQ
+end
+
@@ -0,0 +1,19 @@
+- if @notice
+ .notice= @notice
+
+%h1 RabbitMQ Demo App
+
+%h2 Publish a message
+%form{ :action => "/", :method => "post" }
+ %label
+ Post a message:
+ %input{ :type => "text", :name => "message" }
+ %input{ :type => "submit", :value => "post" }
+
+%h2 Get a message
+%form{ :action => "/message", :method => "get" }
+ %input{ :type => "submit", :value => "get" }
+
+- if @message
+ %h2 Got a message!
+ %p= @message
@@ -0,0 +1,6 @@
+!!!
+%html
+ %head
+ %title= @title || "RabbitMQ Demo"
+ %body
+ = yield

0 comments on commit 603159e

Please sign in to comment.