Sha256: fab176f4d05e26d11d45f7bef8aab94a19b8f527c4d96843f41e5ab40c0148ea

Contents?: true

Size: 913 Bytes

Versions: 6

Compression:

Stored size: 913 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(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

6 entries across 6 versions & 1 rubygems

Version Path
msgr-0.11.0 lib/msgr/binding.rb
msgr-0.11.0.rc3 lib/msgr/binding.rb
msgr-0.11.0.rc2 lib/msgr/binding.rb
msgr-0.11.0.rc1 lib/msgr/binding.rb
msgr-0.10.2 lib/msgr/binding.rb
msgr-0.10.1 lib/msgr/binding.rb