Ack All
Acknowledge all pending KubeMQ queue messages at once in Ruby to confirm an entire batch with a single acknowledgement call.
Overview
ack_all_queue_messages acknowledges every pending message on a channel in a single broker-side call, without receiving them first. Reach for it when you want to drain a queue rather than process it — clearing a backlog of stale work after a bad deploy, resetting a channel between test runs, or discarding messages that are no longer relevant — where pulling and acking each message individually would be slow and wasteful.
Because it settles the whole channel at once, it is far cheaper than a receive-then-ack loop: the broker confirms all in-flight messages atomically and reports how many were affected, using wait_timeout_seconds to bound how long it waits for in-flight transactions to settle before counting.
Gotchas: this is a blunt, irreversible instrument — it acknowledges all currently-pending messages, not a selected subset, so anything unprocessed is discarded, not redelivered. A busy channel may need a larger wait_timeout_seconds to catch messages still landing. For routine, per-message cleanup use ordinary acks, an expiration policy, or a dead-letter policy instead — save ack-all for deliberate, wholesale purges.
Prerequisites
- KubeMQ server running on
localhost:50000 - Ruby SDK installed (
gem install kubemq)
Code
require 'kubemq'
address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')
channel = 'ruby-queues.ack-all'
begin
client = KubeMQ::QueuesClient.new(address: address, client_id: 'qs-ackall-example')
puts "Connected to #{address}"
5.times do |i|
msg = KubeMQ::Queues::QueueMessage.new(channel: channel, metadata: "item-#{i}", body: "data-#{i}")
client.send_queue_message(msg)
end
puts 'Sent 5 messages'
affected = client.ack_all_queue_messages(channel: channel, wait_timeout_seconds: 5)
puts "Acknowledged #{affected} messages"
remaining = client.receive_queue_messages(channel: channel, max_messages: 10, wait_timeout_seconds: 2)
puts "Remaining messages: #{remaining.size}"
rescue KubeMQ::Error => e
puts "KubeMQ error: #{e.message}"
ensure
client&.close
puts 'Done'
endHow It Works
ack_all_queue_messagesremoves all pending messages from the queue in a single operation.- Returns the number of messages that were acknowledged.
- Review timeouts, channel names, and client IDs before running against shared environments.
Related
Was this page helpful?