Class: PikaQue::Connection
- Inherits:
-
Object
- Object
- PikaQue::Connection
show all
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/pika_que/connection.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
init_logger, logger, #logger, logger=
Constructor Details
#initialize(opts = {}) ⇒ Connection
Returns a new instance of Connection.
11
12
13
|
# File 'lib/pika_que/connection.rb', line 11
def initialize(opts = {})
@opts = PikaQue.config.merge(opts)
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
9
10
11
|
# File 'lib/pika_que/connection.rb', line 9
def connection
@connection
end
|
Class Method Details
.create(opts = {}) ⇒ Object
15
16
17
|
# File 'lib/pika_que/connection.rb', line 15
def self.create(opts = {})
new(opts).tap{ |conn| conn.connect! }
end
|
Instance Method Details
#connect! ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/pika_que/connection.rb', line 19
def connect!
@connection ||= Bunny.new(@opts[:amqp], :vhost => @opts[:vhost],
:heartbeat => @opts[:heartbeat],
:properties => @opts.fetch(:properties, {}),
:logger => PikaQue::logger).tap do |conn|
conn.start
end
end
|
#connected? ⇒ Boolean
28
29
30
|
# File 'lib/pika_que/connection.rb', line 28
def connected?
@connection && @connection.connected?
end
|
#disconnect! ⇒ Object
32
33
34
35
|
# File 'lib/pika_que/connection.rb', line 32
def disconnect!
@connection.close if @connection
@connection = nil
end
|
#ensure_connection ⇒ Object
37
38
39
40
41
42
|
# File 'lib/pika_que/connection.rb', line 37
def ensure_connection
unless connected?
@connection = nil
connect!
end
end
|