summaryrefslogtreecommitdiff
path: root/lib/6-chit-chat/publish.rb
blob: e21cb3f6047ceb6a413da08c8d108c6476ae7a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env ruby
## encoding: utf-8

require "bunny"

connection = Bunny.new(host: ENV.fetch('RABBIT_HOST', 'localhost'))
connection.start

channel = connection.create_channel
exchange = channel.topic("chitchat")
username = `'whoami'`.chomp!
message = ARGV.empty? ? "Hi!" : ARGV.join(" ")

exchange.publish(message, routing_key: username)
puts " [x] Sent #{username}:#{message}"

connection.close