Guest User

Untitled

a guest
Jul 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. require 'config'
  2.  
  3. trap('SIGINT') { puts "\nExiting..."; exit(0) }
  4.  
  5. def publish(level, message)
  6. Thread.new do
  7. AMQP.start(:host => HOST) do
  8. exchange = MQ.topic('log')
  9. exchange.publish( {:level => level, :time => Time.now, :body => message}.to_json, :key => "log.#{level}")
  10. AMQP.stop { EM.stop }
  11. # puts "Published message '#{message}' as '#{level}'"
  12. end
  13. end
  14. end
  15.  
  16. publish(:info, 'Purring smoothly...')
  17. publish(:debug, 'Look at this, dude.')
  18. publish(:error, 'BOOM! BOOM!! BOOM!!')
  19.  
  20. puts "-"*80, "Published three initial messages to '#{HOST}'. Have a look in other tabs."
  21.  
  22. puts "Publish message with <LEVEL>: <MESSAGE> command, eg. `info: This is info`", "-"*80
  23.  
  24. while input = gets.chomp do
  25. level, message = input.split(': ')
  26. publish level, message unless [level, message].any? { |i| i.nil? }
  27. end
Add Comment
Please, Sign In to add comment