lib/cotton_tail/queue/bunny.rb in cotton-tail-0.1.1 vs lib/cotton_tail/queue/bunny.rb in cotton-tail-0.1.2

- old
+ new

@@ -10,14 +10,14 @@ end def initialize(name, conn: Connection.new, prefetch: 1, manual_ack: false, **opts) @name = name @prefetch = prefetch - @manual_ack = manual_ack @conn = conn - @closed = false @queue = conn.queue(@name, **opts) + @messages = ::Queue.new + @queue.subscribe(manual_ack: manual_ack) { |*args| @messages << args } end def bind(routing_key) @queue.bind('amq.topic', routing_key: routing_key) end @@ -26,24 +26,22 @@ routing_key, message = args @conn.publish message, routing_key: routing_key end def close - @closed = true + @messages.close end def closed? - @closed + @messages.closed? end def empty? - @queue.message_count.zero? + @messages.empty? end def pop - return if empty? - - delivery_info, *tail = @queue.pop(manual_ack: @manual_ack) + delivery_info, *tail = @messages.pop [delivery_info[:routing_key], delivery_info, *tail, conn: @conn] end end end end