rabbitmq-tutorials/ruby-amqp/receive_logs_topic.rb
Michael Klishin 2ec87888cb ruby => ruby-amqp
ruby should be done with Bunny 0.9 which is much easier to use
for beginners.
2013-07-17 18:07:03 +04:00

31 lines
625 B
Ruby
Executable File

#!/usr/bin/env ruby
# encoding: utf-8
require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.topic("topic_logs")
queue = channel.queue("", :exclusive => true)
if ARGV.empty?
abort "Usage: #{$0} [binding key]"
end
ARGV.each do |binding_key|
queue.bind(exchange, :routing_key => binding_key)
end
Signal.trap("INT") do
connection.close do
EM.stop { exit }
end
end
puts " [*] Waiting for logs. To exit press CTRL+C"
queue.subscribe do |header, body|
puts " [x] #{header.routing_key}:#{body}"
end
end