Sha256: 8997a271786260468324745c00a09133f3114f4d8a83fef73cc563af7cbb751a

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

# Monkey patching some methods into AMQP to make it more testable
module AMQP

  # Initializes new AMQP client/connection without starting another EM loop
  def self.start_connection(opts={}, &block)
#    puts "!!!!!!!!! Existing connection: #{@conn}" if @conn
    @conn = connect opts
    @conn.callback(&block) if block
  end

  # Closes AMQP connection gracefully
  def self.stop_connection
    if AMQP.conn and not AMQP.closing
#   MQ.reset ?
      @closing = true
      @conn.close {
        yield if block_given?
        cleanup_state
      }
    end
  end

  # Cleans up AMQP state after AMQP connection closes
  def self.cleanup_state
#   MQ.reset ?
    Thread.list.each { |thread| thread[:mq] = nil }
    Thread.list.each { |thread| thread[:mq_id] = nil }
    @conn    = nil
    @closing = false
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
amqp-spec-0.3.8 lib/amqp-spec/amqp.rb
amqp-spec-0.3.7 lib/amqp-spec/amqp.rb
amqp-spec-0.3.6 lib/amqp-spec/amqp.rb