Ruby: receive_logs.rb, receive_logs_direct.rb and receive_logs_topic.rb.

This commit is contained in:
Jakub Stastny aka botanicus 2011-05-03 04:48:37 +02:00
parent 4f55a4fcbf
commit 72b4732564
3 changed files with 84 additions and 0 deletions

24
ruby/receive_logs.rb Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env ruby
# encoding: utf-8
require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.fanout("logs")
queue = channel.queue("", :exclusive => true)
queue.bind(exchange)
Signal.trap("INT") do
connection.close do
EM.stop { exit }
end
end
puts " [*] Waiting for logs. To exit press CTRL+C"
queue.subscribe do |body|
puts " [x] #{body}"
end
end

30
ruby/receive_logs_direct.rb Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env ruby
# encoding: utf-8
require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.direct("direct_logs")
queue = channel.queue("", :exclusive => true)
if ARGV.empty?
abort "Usage: #{$0} [info] [warning] [error]"
end
ARGV.each do |severity|
queue.bind(exchange, :routing_key => severity)
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

30
ruby/receive_logs_topic.rb Executable file
View File

@ -0,0 +1,30 @@
#!/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