Skip to content

Commit 72b4732

Browse files
author
Jakub Stastny aka botanicus
committed
Ruby: receive_logs.rb, receive_logs_direct.rb and receive_logs_topic.rb.
1 parent 4f55a4f commit 72b4732

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

ruby/receive_logs.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require "amqp"
5+
6+
AMQP.start(:host => "localhost") do |connection|
7+
channel = AMQP::Channel.new(connection)
8+
exchange = channel.fanout("logs")
9+
queue = channel.queue("", :exclusive => true)
10+
11+
queue.bind(exchange)
12+
13+
Signal.trap("INT") do
14+
connection.close do
15+
EM.stop { exit }
16+
end
17+
end
18+
19+
puts " [*] Waiting for logs. To exit press CTRL+C"
20+
21+
queue.subscribe do |body|
22+
puts " [x] #{body}"
23+
end
24+
end

ruby/receive_logs_direct.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require "amqp"
5+
6+
AMQP.start(:host => "localhost") do |connection|
7+
channel = AMQP::Channel.new(connection)
8+
exchange = channel.direct("direct_logs")
9+
queue = channel.queue("", :exclusive => true)
10+
11+
if ARGV.empty?
12+
abort "Usage: #{$0} [info] [warning] [error]"
13+
end
14+
15+
ARGV.each do |severity|
16+
queue.bind(exchange, :routing_key => severity)
17+
end
18+
19+
Signal.trap("INT") do
20+
connection.close do
21+
EM.stop { exit }
22+
end
23+
end
24+
25+
puts " [*] Waiting for logs. To exit press CTRL+C"
26+
27+
queue.subscribe do |header, body|
28+
puts " [x] #{header.routing_key}:#{body}"
29+
end
30+
end

ruby/receive_logs_topic.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require "amqp"
5+
6+
AMQP.start(:host => "localhost") do |connection|
7+
channel = AMQP::Channel.new(connection)
8+
exchange = channel.topic("topic_logs")
9+
queue = channel.queue("", :exclusive => true)
10+
11+
if ARGV.empty?
12+
abort "Usage: #{$0} [binding key]"
13+
end
14+
15+
ARGV.each do |binding_key|
16+
queue.bind(exchange, :routing_key => binding_key)
17+
end
18+
19+
Signal.trap("INT") do
20+
connection.close do
21+
EM.stop { exit }
22+
end
23+
end
24+
25+
puts " [*] Waiting for logs. To exit press CTRL+C"
26+
27+
queue.subscribe do |header, body|
28+
puts " [x] #{header.routing_key}:#{body}"
29+
end
30+
end

0 commit comments

Comments
 (0)