rabbitmq-tutorials/ruby/emit_log_topic.rb

18 lines
372 B
Ruby

#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
conn = Bunny.new(:automatically_recover => false)
conn.start
ch = conn.create_channel
x = ch.topic("topic_logs")
severity = ARGV.shift || "anonymous.info"
msg = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
x.publish(msg, :routing_key => severity)
puts " [x] Sent #{severity}:#{msg}"
conn.close