# Nack All (/sdks/nodejs/how-to/queues/nack-all)



## Overview [#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 the streaming receive API: `client.streamQueueMessages` delivers batches to an `onMessages` callback without settling them, and `handle.nackAll()` sends one negative-acknowledgment that settles every message in the current batch, 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 `nackAll()` away — pair it with `maxReceiveCount` and a dead-letter policy. `nackAll()` is all-or-nothing: you can't use it to keep a few messages and reject the rest — that needs per-message ack/nack or a range operation. Forgetting `handle.close()` after nacking leaves the streaming session open waiting for another batch.

## Prerequisites [#prerequisites]

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

## Code [#code]

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

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

  try {
    await client.sendQueueMessage(
      createQueueMessage({ channel: 'js-queues-stream.nack-all', body: 'will be nacked' }),
    );

    const handle = client.streamQueueMessages({
      channel: 'js-queues-stream.nack-all',
      maxMessages: 10,
    });
    handle.onMessages((msgs) => {
      console.log('Received', msgs.length, 'message(s) — nacking all');
      handle.nackAll();
      handle.close();
    });
    handle.onError((err) => {
      console.error('Error:', err.message);
    });

    await new Promise((r) => setTimeout(r, 2000));
  } finally {
    await client.close();
  }
}

main().catch(console.error);

```

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

* `streamQueueMessages()` opens a downstream session that delivers a batch of up to `maxMessages` to the `onMessages` callback.
* `handle.nackAll()` sends a single negative-acknowledgment to the server for every message in the current batch, returning them all to the queue at once.
* After `nackAll()`, the messages become available again for redelivery (subject to the visibility timeout and `maxReceiveCount` policy).
* `handle.close()` ends the streaming session after the nack; without it the session would wait for another batch from the server.

## Related [#related]

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