Class: Totoro::SubscribeService

Inherits:
Object
  • Object
show all
Defined in:
lib/totoro/services/subscribe_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SubscribeService

Returns a new instance of SubscribeService.



5
6
7
# File 'lib/totoro/services/subscribe_service.rb', line 5

def initialize(config)
  @config = config
end

Instance Method Details

#channelObject



19
20
21
# File 'lib/totoro/services/subscribe_service.rb', line 19

def channel
  @channel ||= Bunny.new(@config.connect).tap(&:start).create_channel
end

#subscribe(id) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/totoro/services/subscribe_service.rb', line 9

def subscribe(id)
  queue = bind_queue(id)
  queue.purge if @config.clean_start?(id)
  queue.subscribe(manual_ack: @config.manual_ack?(id)) do |delivery_info, , payload|
    yield(delivery_info, , payload)
  ensure
    channel.ack(delivery_info.delivery_tag) if @config.force_ack?(id)
  end
end