Skip to content

Commit 68d4d5b

Browse files
author
Michael Klishin
committed
Make the consumer in Tutorial 1 wait for messages until interrupted
Just like the Java version does.
1 parent 3ef59c7 commit 68d4d5b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ruby/receive.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
ch = conn.create_channel
1010
q = ch.queue("hello")
1111

12-
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
13-
q.subscribe(:block => true) do |delivery_info, properties, body|
14-
puts " [x] Received #{body}"
12+
begin
13+
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
14+
q.subscribe(:block => true) do |delivery_info, properties, body|
15+
puts " [x] Received #{body}"
16+
end
17+
rescue Interrupt => _
18+
puts " [x] Shutting down..."
1519

16-
# cancel the consumer to exit
17-
delivery_info.consumer.cancel
20+
conn.close
1821
end
19-
20-
conn.close

0 commit comments

Comments
 (0)