Ruby: emit_log_direct.rb

This commit is contained in:
Jakub Stastny aka botanicus 2011-05-03 03:55:30 +02:00
parent 6465bd1855
commit f91fe99050
2 changed files with 21 additions and 1 deletions

View File

@ -6,7 +6,7 @@ require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.fanout("logs")
message = (ARGV[1..-1] || ["info: Hello World!"]).join(" ")
message = (ARGV[0..-1] || ["info: Hello World!"]).join(" ")
exchange.publish(message)
puts " [x] Sent #{message}"

20
ruby/emit_log_direct.rb Executable file
View File

@ -0,0 +1,20 @@
#!/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")
severity = ARGV[0] || "info"
message = (ARGV[1..-1] || ["Hello World!"]).join(" ")
exchange.publish(message, :routing_key => severity)
puts " [x] Sent #{severity}:#{message}"
EM.add_timer(0.5) do
connection.close do
EM.stop { exit }
end
end
end