Skip to content

Instantly share code, notes, and snippets.

@adamlwatson
Created November 22, 2011 00:03
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 adamlwatson/1384414 to your computer and use it in GitHub Desktop.
Save adamlwatson/1384414 to your computer and use it in GitHub Desktop.
em-http callbacks not being given time to fire when inside an async callback that is repeatedly triggered?
require 'amqp'
require 'em-http-request'
EM.run do
connection = AMQP.connect(:host => '127.0.0.1')
channel = AMQP::Channel.new(connection)
queue = channel.queue("em.load.test", :auto_delete => true)
exchange = channel.default_exchange
def handle_message(header, payload, *args)
puts "got message: #{payload}"
# call out to a goliath server to get some data based on the incoming message
url = "http://localhost:9000/get_data/#{payload}"
http = EM::HttpRequest.new(url).get
http.callback do
puts "got a response: #{http.response}"
end
http.errback do
puts "an error occurred in the http request!"
end
end
queue.subscribe(&method(:handle_message))
10000.times do |i|
exchange.publish "#{i}", :routing_key => queue.name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment