Ruby: receive_logs.rb, receive_logs_direct.rb and receive_logs_topic.rb.
This commit is contained in:
parent
4f55a4fcbf
commit
72b4732564
24
ruby/receive_logs.rb
Executable file
24
ruby/receive_logs.rb
Executable 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
30
ruby/receive_logs_direct.rb
Executable 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
30
ruby/receive_logs_topic.rb
Executable 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
|
Loading…
Reference in New Issue
Block a user