Permalink
Browse files

Support :manual_ack as well as :ack

  • Loading branch information...
1 parent d1075a1 commit f10370ce54c0b747e6842f99da68546263dc3aa8 Michael Klishin committed Jan 16, 2013
Showing with 31 additions and 3 deletions.
  1. +1 −1 lib/bunny/queue.rb
  2. +30 −2 spec/higher_level_api/integration/basic_consume_spec.rb
View
@@ -109,7 +109,7 @@ def subscribe(opts = {
consumer = Consumer.new(@channel,
self,
ctag,
- !opts[:ack],
+ !(opts[:ack] || opts[:manual_ack]),
opts[:exclusive],
opts[:arguments])
@@ -21,7 +21,7 @@
t = Thread.new do
ch = connection.create_channel
q = ch.queue(queue_name, :auto_delete => true, :durable => false)
- q.subscribe(:exclusive => false, :ack => false) do |delivery_info, properties, payload|
+ q.subscribe(:exclusive => false, :manual_ack => false) do |delivery_info, properties, payload|
delivered_keys << delivery_info.routing_key
delivered_data << payload
end
@@ -46,6 +46,34 @@
context "with manual acknowledgement mode" do
let(:queue_name) { "bunny.basic_consume#{rand}" }
- it "register a consumer with manual acknowledgements mode"
+ it "register a consumer with manual acknowledgements mode" do
+ delivered_keys = []
+ delivered_data = []
+
+ t = Thread.new do
+ ch = connection.create_channel
+ q = ch.queue(queue_name, :auto_delete => true, :durable => false)
+ q.subscribe(:exclusive => false, :manual_ack => true) do |delivery_info, properties, payload|
+ delivered_keys << delivery_info.routing_key
+ delivered_data << payload
+
+ ch.ack(delivery_info.delivery_tag)
+ end
+ end
+ t.abort_on_exception = true
+ sleep 0.5
+
+ ch = connection.create_channel
+ x = ch.default_exchange
+ x.publish("hello", :routing_key => queue_name)
+
+ sleep 0.7
+ delivered_keys.should include(queue_name)
+ delivered_data.should include("hello")
+
+ ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0
+
+ ch.close
+ end
end
end

0 comments on commit f10370c

Please sign in to comment.