KubeMQ
Client SDKsC#How-to guidesQueues

Ack All

Acknowledge all received KubeMQ queue messages at once in a single batch using the C# SDK.

Overview

AckAllQueueMessagesAsync 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 via AffectedMessages on the result.

Gotchas: this is a blunt, irreversible instrument — it acknowledges all currently-pending messages, not a selected subset, so anything unprocessed is discarded, not redelivered. It settles only messages already visible to the broker at call time, so a busy channel can still receive new messages after the call returns. For routine, per-message cleanup use CreateQueueDownstreamReceiverAsync with selective ack or nack, or a dead-letter policy instead — save ack-all for deliberate, wholesale purges.

Prerequisites

  • KubeMQ server running on localhost:50000
  • C# SDK installed (dotnet add package KubeMQ.SDK.CSharp)

Code

Program.cs
// KubeMQ .NET SDK — Queues: Simple AckAll
//
// This example demonstrates acknowledging all pending messages in a queue channel
// using the simple AckAllQueueMessagesAsync API (no stream transaction required).
//
// Prerequisites:
//   - KubeMQ server running on localhost:50000
//   - Send some messages to "csharp-queues.ack-all-simple" first
//   - dotnet run

using KubeMQ.Sdk.Client;

await using var client = new KubeMQClient(new KubeMQClientOptions
{
    ClientId = "csharp-queues-ack-all-simple-client",
});
await client.ConnectAsync();

Console.WriteLine("Connected to KubeMQ server");

var result = await client.AckAllQueueMessagesAsync("csharp-queues.ack-all-simple");
Console.WriteLine($"Acknowledged {result.AffectedMessages} messages");

Console.WriteLine("Done.");

How It Works

  • AckAllQueueMessagesAsync(channelName) is a management-plane call that bulk-acknowledges all pending messages on the named channel without requiring a consumer to receive them first.
  • This is a one-shot operation: messages are removed from the queue immediately. Use it for queue draining (e.g., after a failed deployment) rather than normal processing.
  • The returned result includes AffectedMessages — the count of messages that were acknowledged.
  • For transactional per-message processing with selective ack or nack, use CreateQueueDownstreamReceiverAsync + PollAsync instead.

Was this page helpful?

On this page