Class: StatsdServer::Output::Amqp
- Inherits:
-
Object
- Object
- StatsdServer::Output::Amqp
- Defined in:
- lib/statsdserver/output/amqp.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Amqp
constructor
A new instance of Amqp.
- #send(str) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Amqp
Returns a new instance of Amqp.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/statsdserver/output/amqp.rb', line 8 def initialize(opts = {}) begin require "bunny" rescue LoadError => e raise unless e. =~ /bunny/ new_e = e.exception("Please install the bunny gem for AMQP output.") new_e.set_backtrace(e.backtrace) raise new_e end if opts["exchange_type"].nil? raise ArgumentError, "missing host in [output:amqp] config section" end if opts["exchange_name"].nil? raise ArgumentError, "missing port in [output:amqp] config section" end @opts = opts @logger = Logger.new(STDOUT) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/statsdserver/output/amqp.rb', line 5 def logger @logger end |
Instance Method Details
#send(str) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/statsdserver/output/amqp.rb', line 31 def send(str) if @bunny.nil? @bunny, @exchange = connect end begin @exchange.publish(str) rescue => e @bunny.close_connection rescue nil @bunny = nil raise end end |