Class: BaseRabbitMQRoom

Inherits:
Object
  • Object
show all
Defined in:
lib/postcard_rb/dispatchers/RabbitMQ/routings/BaseRabbitMQRoom.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel:, queue:, exclusive: false) ⇒ BaseRabbitMQRoom

Returns a new instance of BaseRabbitMQRoom.



4
5
6
7
8
# File 'lib/postcard_rb/dispatchers/RabbitMQ/routings/BaseRabbitMQRoom.rb', line 4

def initialize channel:, queue:, exclusive: false
  @channel = channel
  @queue = queue
  @exclusive = exclusive
end

Instance Method Details

#subscribe(block: true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/postcard_rb/dispatchers/RabbitMQ/routings/BaseRabbitMQRoom.rb', line 10

def subscribe block: true
  begin
    manual_ack = false

    manual_ack = true if @exclusive

    @queue.subscribe(manual_ack: manual_ack, block: block) do |delivery_info, properties, payload|
      yield delivery_info, properties, payload

      @channel.ack(delivery_info.delivery_tag) if @exclusive
    end
  rescue Interrupt => _
  
  end
end