Class: MultipleMan::Connection
- Inherits:
-
Object
- Object
- MultipleMan::Connection
- Defined in:
- lib/multiple_man/connection.rb
Instance Attribute Summary collapse
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(channel) ⇒ Connection
constructor
A new instance of Connection.
- #topic_name ⇒ Object
Constructor Details
#initialize(channel) ⇒ Connection
Returns a new instance of Connection.
20 21 22 23 |
# File 'lib/multiple_man/connection.rb', line 20 def initialize(channel) self.channel = channel self.topic = channel.topic(topic_name) end |
Instance Attribute Details
#topic ⇒ Object
Returns the value of attribute topic.
18 19 20 |
# File 'lib/multiple_man/connection.rb', line 18 def topic @topic end |
Class Method Details
.connect ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/multiple_man/connection.rb', line 8 def self.connect channel = connection.create_channel yield new(channel) if block_given? rescue Bunny::Exception reset! retry ensure channel.close if channel && channel.open? end |
.connection ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/multiple_man/connection.rb', line 25 def self.connection @mutex.synchronize do @connection ||= begin connection = Bunny.new(MultipleMan.configuration.connection, heartbeat: 5) MultipleMan.logger.debug "Connecting to #{MultipleMan.configuration.connection}" connection.start connection end end end |
.reset! ⇒ Object
37 38 39 40 41 |
# File 'lib/multiple_man/connection.rb', line 37 def self.reset! @connection.close if @connection @connection = nil end |
Instance Method Details
#topic_name ⇒ Object
43 44 45 |
# File 'lib/multiple_man/connection.rb', line 43 def topic_name MultipleMan.configuration.topic_name end |