Skip to content

Instantly share code, notes, and snippets.

@celldee
Created August 16, 2009 00:35
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 celldee/168503 to your computer and use it in GitHub Desktop.
Save celldee/168503 to your computer and use it in GitHub Desktop.
Simple heartbeat example
require 'bunny'
b = Bunny.new(:logging => true, :heartbeat => 15)
b.start
q = b.queue('hb_test')
Thread.new do
q.subscribe {|msg| puts msg[:payload]}
end
Thread.new do
loop do
sleep(b.heartbeat)
b.send_heartbeat
end
end
loop do
sleep(2 * b.heartbeat)
if b.message_in
puts 'Still alive'
b.message_in = false
else
puts 'Oh dear, no sign of life'
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment