Module: AMQP

Defined in:
lib/amqp-spec/amqp.rb,
lib/version.rb,
lib/amqp-spec/rspec.rb,
lib/amqp-spec/evented_example.rb

Overview

require ‘fiber’ unless Fiber.respond_to?(:current)

Defined Under Namespace

Modules: EMSpec, Spec, SpecHelper

Class Method Summary collapse

Class Method Details

.cleanup_stateObject

Cleans up AMQP state after AMQP connection closes



24
25
26
27
28
29
30
# File 'lib/amqp-spec/amqp.rb', line 24

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

.start_connection(opts = {}, &block) ⇒ Object

Initializes new AMQP client/connection without starting another EM loop



5
6
7
8
9
# File 'lib/amqp-spec/amqp.rb', line 5

def self.start_connection(opts={}, &block)
#    puts "!!!!!!!!! Existing connection: #{@conn}" if @conn
  @conn = connect opts
  @conn.callback(&block) if block
end

.stop_connectionObject

Closes AMQP connection gracefully



12
13
14
15
16
17
18
19
20
21
# File 'lib/amqp-spec/amqp.rb', line 12

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