Sha256: e7a695191254e8abeb03d0b8fd83ac3720868fb50a60c4f7d71f4199785cc779

Contents?: true

Size: 920 Bytes

Versions: 8

Compression:

Stored size: 920 Bytes

Contents

module Msgr

  class Binding
    include Logging

    attr_reader :queue, :subscription, :connection, :route, :dispatcher

    def initialize(connection, route, dispatcher)
      @connection = connection
      @route      = route
      @dispatcher = dispatcher
      @queue      = connection.queue(route.name)

      route.keys.each do |key|
        log(:debug) { "Bind #{key} to #{queue.name}." }

        queue.bind connection.exchange, routing_key: key
      end

      @subscription = queue.subscribe(manual_ack: true) do |*args|
        begin
          dispatcher.call Message.new(connection, *args, route)
        rescue => err
          log(:error) do
            "Rescued error from subscribe: #{err.class.name}: #{err}\n#{err.backtrace.join("\n")}"
          end
        end
      end
    end

    def release
      subscription.cancel
    end

    def delete
      release
      queue.delete
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
msgr-0.14.1 lib/msgr/binding.rb
msgr-0.14.0 lib/msgr/binding.rb
msgr-0.13.0 lib/msgr/binding.rb
msgr-0.12.3 lib/msgr/binding.rb
msgr-0.12.2 lib/msgr/binding.rb
msgr-0.12.1 lib/msgr/binding.rb
msgr-0.12.0 lib/msgr/binding.rb
msgr-0.11.1 lib/msgr/binding.rb