# Ack All (/sdks/nodejs/how-to/queues/ack-all)



## Overview [#overview]

`ackAllQueueMessages` 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 a wait-timeout argument that bounds how long it waits for in-flight messages 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 to catch messages still landing. For routine, per-message cleanup use ordinary acks, an expiration policy, or a [dead-letter policy](/sdks/nodejs/how-to/queues/dead-letter-policy) instead — save ack-all for deliberate, wholesale purges.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Node.js SDK installed (`npm install kubemq-js`)

## Code [#code]

```typescript title="ack-all.ts"
import { KubeMQClient, createQueueMessage } from 'kubemq-js';

async function main() {
  const client = await KubeMQClient.create({
    address: 'localhost:50000',
    clientId: 'js-queues-ack-all-client',
  });

  try {
    for (let i = 1; i <= 5; i++) {
      await client.sendQueueMessage(
        createQueueMessage({ channel: 'js-queues.ack-all', body: `msg-${i}` }),
      );
    }
    console.log('Sent 5 messages');

    const affected = await client.ackAllQueueMessages('js-queues.ack-all', 2);
    console.log('Acknowledged', affected, 'messages');
  } finally {
    await client.close();
  }
}

main().catch(console.error);

```

## How It Works [#how-it-works]

* `ackAllQueueMessages(channel, waitTimeoutSeconds)` is a bulk acknowledgment: it acknowledges all messages currently waiting in the queue without receiving them individually.
* The second argument (`2`) is the wait timeout in seconds — how long to wait for messages to be available before returning.
* The return value is the count of messages that were acknowledged; if the queue is empty it returns `0`.
* This is a destructive operation: messages are permanently removed from the queue. Use it only when you want to discard all pending work (e.g., queue drain on shutdown).

## Related [#related]

* [Pattern overview](/learn/queues/getting-started)
* [Node.js SDK Reference](/sdks/nodejs/reference)
* [Send & Receive](/sdks/nodejs/tutorials/send-receive)
* [Ack & Reject](/sdks/nodejs/how-to/queues/ack-reject)
