Class: Lapine::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/lapine/exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, properties) ⇒ Exchange

Returns a new instance of Exchange.



7
8
9
10
11
12
13
# File 'lib/lapine/exchange.rb', line 7

def initialize(name, properties)
  @name = name
  @props = properties.dup
  @connection_name = props.delete(:connection)
  @exchange_type = props.delete(:type)
  ObjectSpace.define_finalizer(self, proc { |id| Lapine.config.cleanup_exchange(id) })
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



5
6
7
# File 'lib/lapine/exchange.rb', line 5

def conn
  @conn
end

#connection_nameObject (readonly)

Returns the value of attribute connection_name.



5
6
7
# File 'lib/lapine/exchange.rb', line 5

def connection_name
  @connection_name
end

#exchange_typeObject (readonly)

Returns the value of attribute exchange_type.



5
6
7
# File 'lib/lapine/exchange.rb', line 5

def exchange_type
  @exchange_type
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/lapine/exchange.rb', line 5

def name
  @name
end

#propsObject (readonly)

Returns the value of attribute props.



5
6
7
# File 'lib/lapine/exchange.rb', line 5

def props
  @props
end

Instance Method Details

#closeObject



33
34
35
# File 'lib/lapine/exchange.rb', line 33

def close
  @exchange.channel.close
end

#connected?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/lapine/exchange.rb', line 15

def connected?
  @exchange &&
    @exchange.channel &&
    @exchange.channel.connection &&
    @exchange.channel.connection.connected? &&
    @exchange.channel.open?
end

#exchangeObject



23
24
25
26
27
28
29
30
31
# File 'lib/lapine/exchange.rb', line 23

def exchange
  @exchange ||= begin
    conn = Lapine.config.active_connection(connection_name)
    conn.logger.info "Creating channel for #{self.object_id}, thread: #{Thread.current.object_id}"
    channel = conn.create_channel
    Lapine.config.register_channel(self.object_id, channel)
    Bunny::Exchange.new(channel, exchange_type, name, props)
  end
end