KubeMQ
Client SDKsRubyHow-to guidesQueues

Nack All

Negative-acknowledge all KubeMQ queue messages in a batch in Ruby, rejecting them together so the server can redeliver them.

Overview

Bulk nack rejects an entire polled batch of queue messages in a single call instead of settling each one individually. It's the operation you reach for when a failure affects the whole batch at once — a downstream dependency is down, a shared resource lock couldn't be acquired, or a transient error means none of the messages can be processed right now — and retrying them one-by-one would just be extra round-trips for the same outcome.

It works with manual-ack polling: receiver.poll returns a response holding the messages without settling them, and response.nack_all sends one negative-acknowledge that settles every message in that response, returning them all to the queue for redelivery.

Gotchas: the receive count increments on every message in the batch, so an unbounded retry loop is one bad nack_all away — pair it with a max-receive-count and a dead-letter policy. nack_all is all-or-nothing: you can't use it to keep a few messages and reject the rest — that needs per-message settlement. And calling it on an empty response is a wasted round-trip.

Prerequisites

  • KubeMQ server running on localhost:50000
  • Ruby SDK installed (gem install kubemq)

Code

main.rb
require 'kubemq'

address = ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000')
channel = 'ruby-queues.nack-all'

begin
  client = KubeMQ::QueuesClient.new(address: address, client_id: 'qstream-nackall-example')
  puts "Connected to #{address}"

  3.times do |i|
    msg = KubeMQ::Queues::QueueMessage.new(channel: channel, metadata: "item-#{i}", body: "data-#{i}")
    client.send_queue_message(msg)
  end
  puts 'Pre-sent 3 messages'

  receiver = client.create_downstream_receiver
  request = KubeMQ::Queues::QueuePollRequest.new(channel: channel, max_items: 5, wait_timeout: 5)
  response = receiver.poll(request)

  puts "Polled #{response.messages.size} messages — nacking all"
  response.nack_all
  puts 'All messages nacked (returned to queue)'

  response2 = receiver.poll(request)
  puts "Re-polled: #{response2.messages.size} messages available"
  response2.ack_all
rescue KubeMQ::Error => e
  puts "KubeMQ error: #{e.message}"
ensure
  receiver&.close
  client&.close
  puts 'Done'
end

How It Works

  • nack_all negative-acknowledges all messages in the batch, returning them to the queue.
  • Nacked messages become available for redelivery to any consumer.
  • Review timeouts, channel names, and client IDs before running against shared environments.

Was this page helpful?

On this page