Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'config'
- trap('SIGINT') { puts "\nExiting..."; exit(0) }
- def publish(level, message)
- Thread.new do
- AMQP.start(:host => HOST) do
- exchange = MQ.topic('log')
- exchange.publish( {:level => level, :time => Time.now, :body => message}.to_json, :key => "log.#{level}")
- AMQP.stop { EM.stop }
- # puts "Published message '#{message}' as '#{level}'"
- end
- end
- end
- publish(:info, 'Purring smoothly...')
- publish(:debug, 'Look at this, dude.')
- publish(:error, 'BOOM! BOOM!! BOOM!!')
- puts "-"*80, "Published three initial messages to '#{HOST}'. Have a look in other tabs."
- puts "Publish message with <LEVEL>: <MESSAGE> command, eg. `info: This is info`", "-"*80
- while input = gets.chomp do
- level, message = input.split(': ')
- publish level, message unless [level, message].any? { |i| i.nil? }
- end
Add Comment
Please, Sign In to add comment