Skip to main content

Get all messages with pagination using cursor

Since the DLQ can have a large number of messages, they are paginated. You can go through the results using the cursor.
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const all_messages = [];
let cursor = null;
while (true) {
  const res = await client.dlq.listMessages({ cursor });
  all_messages.push(...res.messages);
  cursor = res.cursor;
  if (!cursor) {
    break;
  }
}

List messages with filters

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// filter and paginate with top-level options
const res = await client.dlq.listMessages({
  count: 10,
  order: "latestFirst",
  filter: { url: "https://example.com" }
})

// fetch specific DLQ messages by ID
const res2 = await client.dlq.listMessages({
  dlqIds: ["dlq-id-1", "dlq-id-2"]
})

Delete messages from the DLQ

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// delete a single message
await client.dlq.delete("dlqId");

// delete multiple messages
await client.dlq.delete(["dlq-id-1", "dlq-id-2"]);

// delete with filters
await client.dlq.delete({
  filter: { url: "https://example.com", responseStatus: 500 }
});

// delete all DLQ messages
await client.dlq.delete({ all: true });
client.dlq.deleteMany() is deprecated. Use client.dlq.delete() with an array or filters instead.

Retry messages from the DLQ

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// retry a single message
await client.dlq.retry("dlqId");

// retry multiple messages
await client.dlq.retry(["dlq-id-1", "dlq-id-2"]);

// retry with filters
await client.dlq.retry({
  filter: { queueName: "my-queue" }
});

// retry all DLQ messages
await client.dlq.retry({ all: true });