Sha256: 79682d4da5782aee8e68c5286459057f700cd8192f1f28378622aa34648f027f

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

module SongkickQueue
  class Client
    def default_exchange
      channel.default_exchange
    end

    # Creates a memoized channel for issuing RabbitMQ commands
    #
    # @return [Bunny::Channel]
    def channel
      @channel ||= begin
        channel = connection.create_channel
        channel.prefetch(1)

        channel
      end
    end

    # Creates a memoized connection to RabbitMQ
    #
    # @return [Bunny::Session]
    def connection
      @connection ||= begin
        connection = Bunny.new(config_amqp)
        connection.start

        connection
      end
    end

    private

    # Retrieve the AMQP URL from the configuration
    #
    # @raise [ConfigurationError] if not defined
    def config_amqp
      config.amqp || fail(ConfigurationError, 'missing AMQP URL from config')
    end

    def config
      SongkickQueue.configuration
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
songkick_queue-0.3.0 lib/songkick_queue/client.rb
songkick_queue-0.2.0 lib/songkick_queue/client.rb
songkick_queue-0.1.0 lib/songkick_queue/client.rb