class Totoro::SubscribeService

Public Class Methods

new(config) click to toggle source
# File lib/totoro/services/subscribe_service.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

channel() click to toggle source
# File lib/totoro/services/subscribe_service.rb, line 19
def channel
  @channel ||= Bunny.new(@config.connect).tap(&:start).create_channel
end
subscribe(id) { |delivery_info, metadata, payload| ... } click to toggle source
# 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, metadata, payload|
    yield(delivery_info, metadata, payload)
  ensure
    channel.ack(delivery_info.delivery_tag) if @config.force_ack?(id)
  end
end

Private Instance Methods

bind_queue(id) click to toggle source
# File lib/totoro/services/subscribe_service.rb, line 25
def bind_queue(id)
  exchange_name = @config.exchange_name_for_queue(id)
  if exchange_name.nil?
    channel.queue(*@config.queue(id))
  else
    channel.queue(*@config.queue(id)).bind(exchange_name)
  end
end