Created
August 11, 2009 15:55
-
-
Save celldee/165918 to your computer and use it in GitHub Desktop.
Testing heartbeat monitoring with RabbitMQ and Bunny
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 'bunny' # Change this to point to the test version of bunny.rb otherwise you will probably be asking for the gem | |
require 'timeout' | |
b = Bunny.new(:logging => true, :heartbeat => 30) # Set heartbeat to 30 seconds | |
# Create a new heartbeat frame | |
hb = Qrack::Transport::Heartbeat.new() | |
b.start | |
# Change to channel 0 | |
b.channel = b.channels[0] | |
# Start the subscribe sub-process | |
pid = fork do | |
exec("ruby test_sub.rb") | |
end | |
while true | |
# Get the next frame. Wrap in timeout to deal with overdue heartbeat. | |
begin | |
Timeout::timeout(45) do # timeout set to 45 seconds | |
@f = b.next_frame | |
end | |
rescue Timeout::Error | |
puts 'Killing sub-process' | |
Process.kill("KILL", pid) | |
puts 'Monitor exiting now' | |
exit | |
end | |
if @f.id == 8 | |
b.send_frame(hb) # Send a heartbeat to server | |
else | |
puts 'Cardiac arrest' | |
exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment