Module: AMQP::Hermes::Connectivity
- Included in:
- Receiver, Transmitter
- Defined in:
- lib/amqp-hermes/connectivity.rb
Instance Method Summary collapse
- #channel ⇒ Object
- #close ⇒ Object
- #connection ⇒ Object
- #open? ⇒ Boolean
- #open_channel ⇒ Object
- #open_connection ⇒ Object
Instance Method Details
#channel ⇒ Object
27 28 29 |
# File 'lib/amqp-hermes/connectivity.rb', line 27 def channel @channel || open_channel end |
#close ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/amqp-hermes/connectivity.rb', line 35 def close return if !open? @connection.close AMQP.stop do EventMachine.stop end @connection = nil end |
#connection ⇒ Object
4 5 6 |
# File 'lib/amqp-hermes/connectivity.rb', line 4 def connection @connection || open_connection end |
#open? ⇒ Boolean
23 24 25 |
# File 'lib/amqp-hermes/connectivity.rb', line 23 def open? EventMachine.reactor_running? && !@connection.nil? end |
#open_channel ⇒ Object
31 32 33 |
# File 'lib/amqp-hermes/connectivity.rb', line 31 def open_channel @channel = AMQP::Channel.new(self.connection) end |
#open_connection ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/amqp-hermes/connectivity.rb', line 8 def open_connection return @connection if self.open? # start a ractor if non running unless EventMachine.reactor_running? Thread.new do EventMachine.run end AMQP::Hermes.wait_for(EventMachine, :reactor_running?) end @connection = AMQP.connect end |