Created
November 22, 2011 00:03
-
-
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?
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 '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