lib/msgr/connection.rb in msgr-1.2.0 vs lib/msgr/connection.rb in msgr-1.3.0
- old
+ new
@@ -1,11 +1,10 @@
# frozen_string_literal: true
require 'bunny'
module Msgr
- # rubocop:disable Metrics/ClassLength
class Connection
include Logging
attr_reader :uri, :config
@@ -47,26 +46,39 @@
@exchange ||= channel.exchange
end
def release
return if bindings.empty?
+
log(:debug) { "Release bindings (#{bindings.size})..." }
bindings.each(&:release)
end
def delete
return if bindings.empty?
+
log(:debug) { "Delete bindings (#{bindings.size})..." }
bindings.each(&:delete)
end
def purge(**kwargs)
return if bindings.empty?
+
log(:debug) { "Purge bindings (#{bindings.size})..." }
bindings.each {|b| b.purge(**kwargs) }
+ end
+
+ def purge_queue(name)
+ # Creating the queue in passive mode ensures that queues that do not exist
+ # won't be created just to purge them.
+ # That requires creating a new channel every time, as exceptions (on
+ # missing queues) invalidate the channel.
+ channel.queue(name, passive: true).purge
+ rescue Bunny::NotFound
+ nil
end
def bindings
@bindings ||= []
end