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("<QSTASH_TOKEN>");
const dlq = client.dlq;
const all_messages = [];
let cursor = null;
while (true) {
  const res = await dlq.listMessages({ cursor });
  all_messages.push(...res.messages);
  cursor = res.cursor;
  if (!cursor) {
    break;
  }
}

Delete a message from the DLQ

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

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

await client.dlq.delete("dlqId");

Delete multiple messages from the DLQ

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

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

// using an array of dlqIds
const result = await client.dlq.delete(["dlqId-1", "dlqId-2", "dlqId-3"]);

// or using an object with dlqIds
const result2 = await client.dlq.delete({
  dlqIds: ["dlqId-1", "dlqId-2", "dlqId-3"],
});

console.log(result.deleted); // number of deleted messages

Delete DLQ messages with filters

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

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

// delete by label
const result = await client.dlq.delete({ label: "my-label" });

// delete with multiple filters
const result2 = await client.dlq.delete({
  url: "https://example.com",
  label: "my-label",
  fromDate: "1640995200000",
  toDate: "1672531200000",
});

Retry a single message from the DLQ

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

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

const result = await client.dlq.retry("dlqId");

Retry multiple messages from the DLQ

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

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

// using an array of dlqIds
const result = await client.dlq.retry(["dlqId-1", "dlqId-2"]);

// or using an object with dlqIds
const result2 = await client.dlq.retry({
  dlqIds: ["dlqId-1", "dlqId-2"],
});

console.log(result.responses); // [{ messageId: "..." }, ...]

Retry DLQ messages with filters

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

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

// retry by label
const result = await client.dlq.retry({ label: "my-label" });

// retry with multiple filters
const result2 = await client.dlq.retry({
  url: "https://example.com",
  label: "my-label",
});