Skip to content
Browse files

First Rack example that uses AMQP::Utilities::EventLoopHelper

  • Loading branch information...
1 parent b6d520b commit 2f0fe9127b9808c9392588e7f43cff6d160f6094 @michaelklishin michaelklishin committed May 10, 2011
Showing with 36 additions and 0 deletions.
  1. +36 −0 examples/rack/publish_a_message_on_request/thin.ru
View
36 examples/rack/publish_a_message_on_request/thin.ru
@@ -0,0 +1,36 @@
+use Rack::CommonLogger
+
+require "bundler"
+Bundler.setup
+
+$:.unshift(File.expand_path("../../../../lib", __FILE__))
+
+require 'amqp'
+require 'amqp/utilities/event_loop_helper'
+
+puts "EventMachine.reactor_running? => #{EventMachine.reactor_running?.inspect}"
+
+AMQP::Utilities::EventLoopHelper.run do
+ AMQP.start
+
+ exchange = AMQP.channel.fanout("amq.fanout")
+
+ q = AMQP.channel.queue("", :auto_delete => true, :exclusive => true)
+ q.bind(exchange)
+ AMQP::channel.default_exchange.publish("Started!", :routing_key => q.name)
+end
+
+app = proc do |env|
+ AMQP.channel.fanout("amq.fanout").publish("Served a request at (#{Time.now.to_i})")
+
+ [
+ 200, # Status code
+ { # Response headers
+ 'Content-Type' => 'text/html',
+ 'Content-Length' => '2',
+ },
+ ['hi'] # Response body
+ ]
+end
+
+run app

0 comments on commit 2f0fe91

Please sign in to comment.
Something went wrong with that request. Please try again.