Class: EventPeople::Broker::Rabbit::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/event_people/broker/rabbit/queue.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ Queue

Returns a new instance of Queue.



4
5
6
7
# File 'lib/event_people/broker/rabbit/queue.rb', line 4

def initialize(channel)
  @channel = channel
  @channel.prefetch(1)
end

Class Method Details

.subscribe(channel, routing_key, &block) ⇒ Object



9
10
11
# File 'lib/event_people/broker/rabbit/queue.rb', line 9

def self.subscribe(channel, routing_key, &block)
  new(channel).subscribe(routing_key, &block)
end

Instance Method Details

#subscribe(routing_key, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/event_people/broker/rabbit/queue.rb', line 13

def subscribe(routing_key, &block)
  base_name = routing_key.split('.')[0..2].join('.')
  name = queue_name("#{base_name}.all")

  channel.queue(name, queue_options)
         .bind(topic, routing_key: routing_key)
         .subscribe(manual_ack: true) do |delivery_info, properties, payload|
           callback(delivery_info, properties, payload, &block)
         end
end