Created
May 19, 2009 20:44
-
-
Save kennethkalmer/114388 to your computer and use it in GitHub Desktop.
This file contains 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 'rubygems' | |
require 'timeout' | |
require 'mq' | |
10.times do |i| | |
puts "Run: #{i}" | |
em = Thread.new { EM.run } | |
q = MQ.queue("test#{i}") | |
@msg = nil | |
q.subscribe { |msg| @msg = msg } | |
q.publish i | |
begin | |
Timeout::timeout(5) do | |
loop do | |
break unless @msg.nil? | |
sleep 1 | |
end | |
puts "MSG: #{@msg}" | |
end | |
rescue Timeout::Error | |
puts "Timeout on test#{i}" | |
end | |
AMQP.stop { EM.stop } | |
em.join | |
puts "------------" | |
end |
This file contains 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
$ r amqp.rb | |
Run: 0 | |
MSG: 0 | |
------------ | |
Run: 1 | |
Timeout on test1 | |
------------ | |
Run: 2 | |
Timeout on test2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment