Skip to content

Instantly share code, notes, and snippets.

@gareth
Created October 9, 2012 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gareth/3858428 to your computer and use it in GitHub Desktop.
Save gareth/3858428 to your computer and use it in GitHub Desktop.
require 'json'
require 'eventmachine'
require 'sinatra/async'
class Main
register Sinatra::Async
def self.handleMessage(channel, message)
puts "Handling message for channel #{channel}: #{message}"
end
configure do
REDISPUBSUB = Redis.new(monk_settings(:redis))
PUBSUBTHREAD = Thread.new(self) { |main|
REDISPUBSUB.psubscribe("channel.*") do |on|
on.psubscribe do |event, total|
puts "Subscribed to #{event} (#{total} subscriptions)"
end
on.pmessage do |pattern, channel, message|
puts "Fielding message: #{message}"
puts "#{main.method(:handleMessage)}"
main.handleMessage(channel, message)
end
end
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment