rabbitmq-tutorials/ruby/receive_logs_topic.rb
Michael Klishin 2316088e96 Disable automatic connection recovery for Bunny tutorials
It's not needed and will help investigate obscure exceptions
in CI environment.
2013-07-25 09:57:39 +04:00

33 lines
582 B
Ruby

#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
if ARGV.empty?
abort "Usage: #{$0} [binding key]"
end
conn = Bunny.new(:automatically_recover => false)
conn.start
ch = conn.create_channel
x = ch.topic("topic_logs")
q = ch.queue("", :exclusive => true)
ARGV.each do |severity|
q.bind(x, :routing_key => severity)
end
puts " [*] Waiting for logs. To exit press CTRL+C"
begin
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] #{delivery_info.routing_key}:#{body}"
end
rescue Interrupt => _
ch.close
conn.close
exit(0)
end