Tutorial 4 ported to Bunny
This commit is contained in:
parent
8b5971a1eb
commit
bd8b41363b
18
ruby/emit_log_direct.rb
Normal file
18
ruby/emit_log_direct.rb
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env ruby
|
||||
# encoding: utf-8
|
||||
|
||||
require "bunny"
|
||||
|
||||
conn = Bunny.new
|
||||
conn.start
|
||||
|
||||
ch = conn.create_channel
|
||||
x = ch.direct("direct_logs")
|
||||
severity = ARGV.shift || "info"
|
||||
msg = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
|
||||
|
||||
x.publish(msg, :routing_key => severity)
|
||||
puts " [x] Sent '#{msg}'"
|
||||
|
||||
sleep 0.5
|
||||
conn.close
|
32
ruby/receive_logs_direct.rb
Normal file
32
ruby/receive_logs_direct.rb
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env ruby
|
||||
# encoding: utf-8
|
||||
|
||||
require "bunny"
|
||||
|
||||
if ARGV.empty?
|
||||
abort "Usage: #{$0} [info] [warning] [error]"
|
||||
end
|
||||
|
||||
conn = Bunny.new
|
||||
conn.start
|
||||
|
||||
ch = conn.create_channel
|
||||
x = ch.direct("direct_logs")
|
||||
q = ch.queue("", :exclusive => true)
|
||||
|
||||
ARGV.each do |severity|
|
||||
q.bind(x, :routing_key => severity)
|
||||
end
|
||||
|
||||
puts " [*] Waiting for logs. To exit press CTRL+C"
|
||||
|
||||
begin
|
||||
q.subscribe(:block => true) do |delivery_info, properties, body|
|
||||
puts " [x] #{body}"
|
||||
end
|
||||
rescue Interrupt => _
|
||||
puts " [*] Shutting down..."
|
||||
|
||||
ch.close
|
||||
conn.close
|
||||
end
|
Loading…
Reference in New Issue
Block a user