Skip to content

Instantly share code, notes, and snippets.

@kennethkalmer
Created May 19, 2009 20:44
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 kennethkalmer/114388 to your computer and use it in GitHub Desktop.
Save kennethkalmer/114388 to your computer and use it in GitHub Desktop.
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
$ 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