Class: Lapine::Exchange
- Inherits:
-
Object
- Object
- Lapine::Exchange
- Defined in:
- lib/lapine/exchange.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#connection_name ⇒ Object
readonly
Returns the value of attribute connection_name.
-
#exchange_type ⇒ Object
readonly
Returns the value of attribute exchange_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
Instance Method Summary collapse
- #close ⇒ Object
- #connected? ⇒ Boolean
- #exchange ⇒ Object
-
#initialize(name, properties) ⇒ Exchange
constructor
A new instance of Exchange.
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
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
5 6 7 |
# File 'lib/lapine/exchange.rb', line 5 def conn @conn end |
#connection_name ⇒ Object (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_type ⇒ Object (readonly)
Returns the value of attribute exchange_type.
5 6 7 |
# File 'lib/lapine/exchange.rb', line 5 def exchange_type @exchange_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/lapine/exchange.rb', line 5 def name @name end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
5 6 7 |
# File 'lib/lapine/exchange.rb', line 5 def props @props end |
Instance Method Details
#close ⇒ Object
33 34 35 |
# File 'lib/lapine/exchange.rb', line 33 def close @exchange.channel.close end |
#connected? ⇒ 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 |
#exchange ⇒ Object
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 |