Make the consumer in Tutorial 1 wait for messages until interrupted

Just like the Java version does.
This commit is contained in:
Michael Klishin 2013-07-19 06:34:52 +04:00
parent 3ef59c7f26
commit 68d4d5b718

View File

@ -9,12 +9,13 @@ conn.start
ch = conn.create_channel
q = ch.queue("hello")
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}"
begin
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}"
end
rescue Interrupt => _
puts " [x] Shutting down..."
# cancel the consumer to exit
delivery_info.consumer.cancel
conn.close
end
conn.close