# Requeue All (/sdks/nodejs/how-to/queues/requeue-all)



## Overview [#overview]

**Requeue all** moves an entire batch of received messages to a different channel in one server-side operation, without republishing them from the client. Reach for it when you need to make a routing decision after looking at a batch — shovel a stuck batch into a review queue, redirect it to a priority pipeline, or migrate messages off a channel that's being retired, all while the source queue is cleared atomically.

It works against the batch delivered to a streaming handle: inside `onMessages`, call `handle.reQueueAll(targetChannel)` to move every message in that batch to the target channel in one call, removing them from the source at the same instant. The messages keep their original body, tags, and policies — the broker relocates them, it doesn't recreate them.

**Gotchas:** requeuing is all-or-nothing for the batch — there's no per-message filter, so split the batch yourself first if only some messages should move. The destination channel is an ordinary queue with no special semantics; nothing consumes it automatically. And the operation only affects messages still held in that streamed batch — anything already acked, nacked, or expired beforehand is gone before `reQueueAll` runs.

## Prerequisites [#prerequisites]

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

## Code [#code]

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

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

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

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

    await new Promise((r) => setTimeout(r, 2000));
    console.log(
      'Messages moved from js-queues-stream.requeue-all to js-queues-stream.requeue-all-target',
    );
  } finally {
    await client.close();
  }
}

main().catch(console.error);

```

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

* `handle.reQueueAll(targetChannel)` atomically moves all messages in the current streaming batch to a different queue channel in a single server call.
* The messages are removed from `js-queues-stream.requeue-all` and enqueued in `js-queues-stream.requeue-all-target` while preserving their original bodies, tags, and policies.
* This is the stream API equivalent of forwarding: useful for routing messages to priority queues, retry queues, or topic-specific queues based on content inspection.
* `handle.close()` ends the streaming session immediately after the requeue; the outer `setTimeout` acts as a safety wait before logging the completion message.

## 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)
