Created
February 12, 2009 04:25
-
-
Save careo/62486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| #require "#{File.dirname(__FILE__)}/easy_sin" | |
| require 'rubygems' | |
| require 'mq' | |
| require 'json' | |
| require 'uuid' | |
| require 'rabbited_sinatra' | |
| EM.run { | |
| def log *args | |
| p args | |
| end | |
| amq = MQ.new | |
| amq.queue(UUID.generate,:auto_delete => true).bind(amq.topic('requests',:auto_delete => true)).subscribe{ |info,request| | |
| env = JSON.parse(request) | |
| # Massage some rack values back into shape | |
| input = env.delete 'rack.input' | |
| env['rack.input'] = StringIO.new(input) | |
| #resp = [200, {'Content-Type' => 'text/plain'}, "Oh, Hai!"] | |
| sinatra = Sinatra::Application.new | |
| resp = sinatra.call(env) | |
| if info.reply_to | |
| amq.queue(info.reply_to).publish(resp.to_json, :key => info.reply_to, :message_id => info.message_id) | |
| end | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment