Permalink
Browse files

Switch to RabbitMQ.

  • Loading branch information...
1 parent fc24391 commit 310d484f1b1bc1ae01e678e2fa9c037c234bff93 @cmeiklejohn cmeiklejohn committed Jan 9, 2013
Showing with 44 additions and 26 deletions.
  1. +1 −1 Gemfile
  2. +10 −3 Gemfile.lock
  3. +8 −0 config.ru
  4. +15 −10 lib/giddyup/bootstrap.rb
  5. +2 −2 lib/giddyup/contexts.rb
  6. +8 −10 lib/giddyup/resources.rb
View
@@ -11,7 +11,7 @@ gem 'pg'
gem 'rake'
gem 'puma'
gem 'rack-rewrite'
-gem 'redis'
+gem 'amqp'
group :assets do
gem 'rake-pipeline', :git => 'git://github.com/livingsocial/rake-pipeline.git',
View
@@ -32,10 +32,18 @@ GEM
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
+ amq-client (0.9.10)
+ amq-protocol (>= 0.9.4)
+ eventmachine
+ amq-protocol (1.0.1)
+ amqp (0.9.8)
+ amq-client (~> 0.9.5)
+ amq-protocol (>= 0.9.4)
+ eventmachine
arel (3.0.2)
builder (3.0.4)
+ eventmachine (1.0.0)
excon (0.16.10)
- excon (0.16.2)
execjs (1.4.0)
multi_json (~> 1.0)
fog (1.8.0)
@@ -63,7 +71,6 @@ GEM
rack (1.4.1)
rack-rewrite (1.3.1)
rake (0.9.5)
- redis (3.0.2)
ruby-hmac (0.4.0)
thor (0.16.0)
tilt (1.3.3)
@@ -81,6 +88,7 @@ PLATFORMS
DEPENDENCIES
active_model_serializers
activerecord
+ amqp
bundler (~> 1.2.0)
fog
oj
@@ -91,7 +99,6 @@ DEPENDENCIES
rake
rake-pipeline!
rake-pipeline-web-filters!
- redis
tilt
uglifier
webmachine
View
@@ -4,6 +4,7 @@ require 'bundler'
Bundler.require
+require 'amqp'
require 'giddyup'
require 'rack/static'
require 'rack-rewrite'
@@ -16,6 +17,13 @@ use Rack::Rewrite do
rewrite %r{^(.*)\/$}, '$1/index.html'
end
+EventMachine.run do
+ AMQP.connect(:host => "127.0.0.1") do |connection|
+ AMQP.channel ||= AMQP::Channel.new(connection)
+ AMQP.channel.queue("events", :auto_delete => true)
+ end
+end
+
use Rake::Pipeline::Middleware, "Assetfile"
use Rack::Static, :urls => ["/index.html", "/favicon.ico", "/stylesheets", "/javascripts", "/images"], :root => "public"
run GiddyUp::Application.adapter
View
@@ -38,17 +38,22 @@
GiddyUp::AUTH_USER = ENV['AUTH_USER']
GiddyUp::AUTH_PASSWORD = ENV['AUTH_PASSWORD']
-### RedisToGo Setup
-require 'redis'
-REDISURL = URI.parse(ENV['REDISTOGO_URL'])
-
module GiddyUp
- module Redis
- def self.new
- ::Redis.new(:host => REDISURL.host,
- :port => REDISURL.port,
- :password => REDISURL.password,
- :timeout => 0)
+ class Events
+ attr_accessor :queue, :exchange
+
+ def initialize
+ @queue = "events"
+ @channel = AMQP.channel
+ @exchange = channel.default_exchange
+ end
+
+ def publish(event)
+ exchange.publish event, :routing_key => queue.name
+ end
+
+ def subscribe(&block)
+ channel.subscribe block
end
end
end
View
@@ -4,7 +4,7 @@ module GiddyUp
class CreateTestResult
def initialize
@test_result = TestResult.new
- @redis = GiddyUp::Redis.new
+ @events = GiddyUp::Events.new
end
def id
@@ -33,7 +33,7 @@ def create_test_result(data)
def publish_test_result
result = TestResultSerializer.new(@test_result)
- @redis.publish 'events', JSON.generate({
+ @events.publish JSON.generate({
:id => id,
:event => 'test_result',
:data => { :test_result => result.serializable_hash }
View
@@ -77,7 +77,7 @@ def query_ids
class LiveResource < Webmachine::Resource
def initialize
- @redis = GiddyUp::Redis.new
+ @events = GiddyUp::Events.new
set_headers
end
@@ -96,15 +96,13 @@ def content_types_provided
def to_event
Fiber.new do |f|
- @redis.subscribe('events') do |on|
- on.message do |channel, msg|
- message = JSON.parse(msg)
- id = message["id"]
- event = message["event"]
- data = JSON.generate(message["data"])
-
- Fiber.yield "id: #{id}\nevent: #{event}\ndata: #{data}\n\n"
- end
+ @events.subscribe do |msg|
+ message = JSON.parse(msg)
+ id = message["id"]
+ event = message["event"]
+ data = JSON.generate(message["data"])
+
+ Fiber.yield "id: #{id}\nevent: #{event}\ndata: #{data}\n\n"
end
end
end

0 comments on commit 310d484

Please sign in to comment.