Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created July 10, 2009 08:51
Show Gist options
  • Save maxlapshin/144354 to your computer and use it in GitHub Desktop.
Save maxlapshin/144354 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'active_support'
require 'haml'
require 'thin'
gem 'tmm1-amqp'
require 'mq'
Sinatra::Default.set(
:run => false,
:raise_errors => true
)
class Chat < Sinatra::Base
use_in_file_templates!(__FILE__)
get '/' do
@message = "Hi"
haml :index
end
get "/jquery.js" do
send_file(File.dirname(__FILE__)+"/../jquery.js")
end
end
EM.run do
connection = AMQP.connect(:host => '127.0.0.1', :port => 5672, :logging => false)
amq = MQ.new(connection)
control = amq.direct('control')
EM.add_periodic_timer(5) {
puts "Tick"
control.publish({:command => "LIST"}.to_json, :key => "app.server")
}
MQ::Queue.new(amq, "auth.server").bind(control, :key => "auth.server").subscribe do |headers, data|
puts data
end
app = Rack::URLMap.new('/' => Chat.new)
Thin::Server.start('0.0.0.0', 4567, app)
end
__END__
@@ layout
%html
%meta{"http-equiv" => "Content-Type", :content => "text/html; charset=utf8"}
%script{ :type => "text/javascript", :src => "/jquery.js"}
%body
= yield
@@ index
#test Hi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment