Sha256: 70e1a2547c7cb26daa4ceff5795276a17af2266f4f49f674ed3aabb8cead7987

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

module Totoro
  class SubscribeService
    def initialize(config)
      @config = config
    end

    def subscribe(id)
      queue = bind_queue(id)
      queue.purge if @config.clean_start?
      queue.subscribe do |delivery_info, metadata, payload|
        yield(delivery_info, metadata, payload)
      end
    end

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

    private

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
totoro-1.0.4 lib/totoro/services/subscribe_service.rb