main
 1#!/usr/bin/env ruby
 2## encoding: utf-8
 3
 4require "bunny"
 5
 6if ARGV.empty?
 7  abort "Usage: #{$0} [binding key]"
 8end
 9
10connection = Bunny.new
11connection.start
12
13channel = connection.create_channel
14exchange = channel.topic("topic_logs")
15queue = channel.queue("", exclusive: true)
16
17ARGV.each do |severity|
18  queue.bind(exchange, routing_key: severity)
19end
20
21puts " [*] Waiting for logs. To exit press CTRL+C"
22
23begin
24  queue.subscribe(block: true) do |delivery_info, properties, body|
25    puts " [x] #{delivery_info.routing_key}:#{body}"
26  end
27rescue Interrupt => _
28  channel.close
29  connection.close
30end