ruby-amqp/bunny — pull request #63 by celldee (2012-11-16 15:22:57+00:00)
Title: Patch for manual queue.subscription acknowledgements 

Hi Michael,

I have added a new argument to the queue.subscription - :auto_ack - which allows the :ack flag to be set to true without automatically acknowledging messages. This allows the following to be possible -

#!/usr/bin/env ruby
require 'bunny'

# Create a new empty queue.
bunny = Bunny.new
bunny.start
queue = bunny.queue('test')
queue.purge

# Create a new exchange and publish two messages to the 'test' queue.
exchange = bunny.exchange('', :key => 'test')
exchange.publish('hello')
exchange.publish('world')
# Let RabbitMQ process the messages.
sleep 0.2
# Consume all messages from the queue without acknowledging them.
begin
queue.subscribe(:ack => true, :auto_ack => false, :timeout => 0.5) do |msg|
p msg
end
rescue Timeout::Error
end

# Reset connection.
bunny.stop
sleep 0.1
bunny.start
puts "--------"

# We should now receive both messages again.
queue = bunny.queue('test')
p queue.pop
p queue.pop

The benefit of a new argument it that existing behaviour is not affected.

I've also amended some failing tests and bumped the version number.

I've tested with Ruby 1.8.7/1.9.2/1.9.3 and JRuby 1.7.0 against RabbitMQ 2.8.7.

Cheers,

Chris