Skip to content

Instantly share code, notes, and snippets.

@hassox
Forked from careo/disconnect.rb
Created February 17, 2010 23:11
Show Gist options
  • Select an option

  • Save hassox/307122 to your computer and use it in GitHub Desktop.

Select an option

Save hassox/307122 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'amqp'
require 'mq'
EM.error_handler {|e|
p [:exception, e]
}
EM.run do
AMQP.start
q = MQ.queue("failure_test", :auto_delete => true)
EM.add_periodic_timer(1) do
msg = Time.now.to_s
puts "Publishing: #{msg.inspect}"
q.publish(msg)
end
q.subscribe do |msg|
puts "Received: #{msg.inspect}"
end
end
# When starting with no rabbit up
∴ ruby failover_test.rb
[:exception, #<AMQP::Error: Could not connect to server 127.0.0.1:5672>]
Publishing: "Thu Feb 18 10:14:06 +1100 2010"
Publishing: "Thu Feb 18 10:14:07 +1100 2010"
Publishing: "Thu Feb 18 10:14:08 +1100 2010"
Publishing: "Thu Feb 18 10:14:09 +1100 2010"
Publishing: "Thu Feb 18 10:14:10 +1100 2010"
Publishing: "Thu Feb 18 10:14:11 +1100 2010"
Publishing: "Thu Feb 18 10:14:12 +1100 2010"
# Killing rabbit part way through and then re-starting it
∴ ruby failover_test.rb
Publishing: "Thu Feb 18 10:15:42 +1100 2010"
Received: "Thu Feb 18 10:15:42 +1100 2010"
Publishing: "Thu Feb 18 10:15:44 +1100 2010"
Received: "Thu Feb 18 10:15:44 +1100 2010"
Publishing: "Thu Feb 18 10:15:45 +1100 2010"
Publishing: "Thu Feb 18 10:15:46 +1100 2010"
Publishing: "Thu Feb 18 10:15:47 +1100 2010"
Publishing: "Thu Feb 18 10:15:48 +1100 2010"
Publishing: "Thu Feb 18 10:15:49 +1100 2010"
Publishing: "Thu Feb 18 10:15:50 +1100 2010"
Publishing: "Thu Feb 18 10:15:51 +1100 2010"
Received: "Thu Feb 18 10:15:46 +1100 2010"
Received: "Thu Feb 18 10:15:47 +1100 2010"
Received: "Thu Feb 18 10:15:48 +1100 2010"
Received: "Thu Feb 18 10:15:49 +1100 2010"
Received: "Thu Feb 18 10:15:50 +1100 2010"
Received: "Thu Feb 18 10:15:51 +1100 2010"
Publishing: "Thu Feb 18 10:15:52 +1100 2010"
Received: "Thu Feb 18 10:15:52 +1100 2010"
Publishing: "Thu Feb 18 10:15:53 +1100 2010"
Received: "Thu Feb 18 10:15:53 +1100 2010"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment