Skip to content

Commit 959159e

Browse files
committed
Add Channel#confirm_select and #fetch_confirm.
1 parent c028dbc commit 959159e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/rabbitmq/channel.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ def tx_rollback
222222
fetch_response :tx_rollback_ok
223223
end
224224

225+
##
226+
# Confirm mode operations
227+
228+
def confirm_select
229+
send_request :confirm_select
230+
fetch_response :confirm_select_ok
231+
end
232+
233+
def fetch_confirm
234+
fetch_response [:basic_ack, :basic_nack, :basic_reject]
235+
end
236+
225237
##
226238
# Message operations
227239

spec/channel_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,23 @@
317317
res.has_key?(:header).should_not be
318318
end
319319

320+
it "can work with publish confirms" do
321+
res = subject.confirm_select
322+
res[:properties].should be_empty
323+
324+
subject.queue_delete("my_queue")
325+
subject.queue_declare("my_queue")
326+
327+
messages = 100.times.map { |i| "message_#{i}" }
328+
messages.each do |message|
329+
res = subject.basic_publish(message, "", "my_queue")
330+
res.should eq true
331+
end
332+
333+
loop do
334+
res = subject.fetch_confirm
335+
fail unless res.fetch(:method) == :basic_ack
336+
break if res.fetch(:properties).fetch(:delivery_tag) == 100
337+
end
338+
end
320339
end

0 commit comments

Comments
 (0)