lib/cotton_tail/queue/bunny.rb in cotton-tail-0.6.1 vs lib/cotton_tail/queue/bunny.rb in cotton-tail-0.7.0

- old
+ new

@@ -6,22 +6,19 @@ module CottonTail module Queue # A wrapper around a ::Bunny::Queue that makes it interchangeable with a # standard Ruby Queue class Bunny < SimpleDelegator - extend Forwardable - def self.call(**opts) new(**opts) end def initialize(name:, connection:, manual_ack: false, **opts) super ::Queue.new - @name = name - @source_opts = opts @connection = connection + @source = build_source(name, opts) watch_source manual_ack end def push(request) @@ -38,17 +35,23 @@ source.bind('amq.topic', routing_key: Route.new(routing_key).binding) end private - attr_reader :connection + attr_reader :connection, :source + def nil_opts(opts) + { exclusive: true }.merge(opts) + end + def watch_source(manual_ack) source.subscribe(manual_ack: manual_ack) { |*args| self << args } end - def source - @source ||= channel.queue(@name, **@source_opts) + def build_source(name, opts) + return channel.queue('', **nil_opts(opts)) if name.nil? + + channel.queue(name, **opts) end def channel @channel ||= connection.create_channel end