Class: Freddy::Adapters::BunnyAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/freddy/adapters/bunny_adapter.rb

Defined Under Namespace

Classes: Channel, Queue

Constant Summary collapse

DEFAULT_OPTIONS =
{
  connection_timeout: 5,
  read_timeout: 5,
  write_timeout: 5
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bunny) ⇒ BunnyAdapter

Returns a new instance of BunnyAdapter.



21
22
23
# File 'lib/freddy/adapters/bunny_adapter.rb', line 21

def initialize(bunny)
  @bunny = bunny
end

Class Method Details

.connect(config) ⇒ Object



15
16
17
18
19
# File 'lib/freddy/adapters/bunny_adapter.rb', line 15

def self.connect(config)
  bunny = Bunny.new(DEFAULT_OPTIONS.merge(config))
  bunny.start
  new(bunny)
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/freddy/adapters/bunny_adapter.rb', line 31

def close
  @bunny.close
end

#create_channel(prefetch: nil) ⇒ Object



25
26
27
28
29
# File 'lib/freddy/adapters/bunny_adapter.rb', line 25

def create_channel(prefetch: nil)
  bunny_channel = @bunny.create_channel
  bunny_channel.prefetch(prefetch) if prefetch
  Channel.new(bunny_channel)
end