main
 1#!/usr/bin/env ruby
 2## encoding: utf-8
 3
 4require "bunny"
 5
 6connection = Bunny.new(host: ENV.fetch('RABBIT_HOST', 'localhost'))
 7connection.start
 8
 9channel = connection.create_channel
10exchange = channel.topic("chitchat")
11username = `'whoami'`.chomp!
12
13begin
14  print "> "
15  while message = gets do
16    exchange.publish(message, routing_key: username)
17    puts " [x] Sent #{username}:#{message}"
18    print "> "
19  end
20rescue
21  connection.close
22end
23