Class: RailwayIpc::ConnectionManager
- Inherits:
-
Object
- Object
- RailwayIpc::ConnectionManager
- Includes:
- Singleton
- Defined in:
- lib/railway_ipc/connection_manager.rb
Overview
RabbitMQ connection manager. Ensures there is a single RabbitMQ connection and channel per thread, which prevents channel leaks.
Instance Method Summary collapse
- #channel ⇒ Object
- #connected? ⇒ Boolean
- #establish_connection ⇒ Object
-
#initialize ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
Constructor Details
#initialize ⇒ ConnectionManager
Returns a new instance of ConnectionManager.
12 13 14 |
# File 'lib/railway_ipc/connection_manager.rb', line 12 def initialize establish_connection end |
Instance Method Details
#channel ⇒ Object
31 32 33 34 35 36 |
# File 'lib/railway_ipc/connection_manager.rb', line 31 def channel return @channel if connected? establish_connection @channel end |
#connected? ⇒ Boolean
38 39 40 |
# File 'lib/railway_ipc/connection_manager.rb', line 38 def connected? @connection&.connected? && @channel&.open? end |
#establish_connection ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/railway_ipc/connection_manager.rb', line 16 def establish_connection @connection = Bunny.new( host: settings[:host], user: settings[:user], pass: settings[:pass], port: settings[:port], vhost: settings[:vhost] || '/', logger: RailwayIpc.logger ) @connection.start @channel = @connection.create_channel @connection end |