Class: Hopper::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/hopper/channel.rb,
lib/hopper/channel/queue.rb,
lib/hopper/channel/queue/listener.rb,
lib/hopper/channel/queue/publisher.rb

Defined Under Namespace

Classes: Proxy, Queue

Instance Method Summary collapse

Constructor Details

#initializeChannel

Returns a new instance of Channel.



19
20
21
22
23
24
25
26
27
# File 'lib/hopper/channel.rb', line 19

def initialize
  conn = Bunny.new
  conn.start

  @bunny = conn.create_channel
  @bunny.prefetch(1)

  @queues = {}
end

Instance Method Details

#queue(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hopper/channel.rb', line 29

def queue(name)
  if @queues.has_key?(name)
    @queues[name] 
  else
    #TODO: This violates SRP. We both manage caching the queues and
    #constructing a bunch of intermediate objects. I'm wondering if this
    #belongs more in a factory somewhere else.
    queue = Hopper::Queue.new(name)
    proxy = Hopper::Channel::Proxy.new(self, @bunny)
    @queues[name] = Hopper::Channel::Queue.new(proxy, queue)
  end
end