Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

Dead Letter Queue (DLQ)

The Dead Letter Queue (DLQ) manages messages that have failed delivery after exhausting all retry attempts. This guide covers how to view, manage, and retry failed messages.

The Dead Letter Queue (DLQ) manages messages that have failed delivery after exhausting all retry attempts. This guide covers how to view, manage, and retry failed messages.

Overview

When a message fails to deliver after all retry attempts, it’s moved to the Dead Letter Queue. The DLQ allows you to:

  • View failed messages
  • Inspect failure reasons
  • Retry failed messages
  • Delete messages from the queue
  • Export DLQ data for analysis

Every DLQ operation is scoped to the environment your credential belongs to. A staging key sees, replays and deletes only staging’s failed messages; production failures are not visible to it and return 404 by ID.

Understanding Message Failures

Messages are moved to the DLQ when:

  1. HTTP Errors: 4xx or 5xx status codes after all retries
  2. Timeout: Request exceeds the configured timeout
  3. Network Errors: Connection failures, DNS errors, etc.
  4. Invalid Response: Malformed or unexpected responses

Listing DLQ Messages

Get All Failed Messages

curl https://api.anlyon.com/api/v2/dlq \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Query Parameters

Parameter Type Description
page number Page number (default: 1)
limit number Items per page (default: 20, max: 100)
startDate string Filter messages failed after this date
endDate string Filter messages failed before this date
url string Filter by destination URL

Response

{
  "success": true,
  "data": [
    {
      "messageId": "msg_1234567890abcdef",
      "url": "https://example.com/webhook",
      "method": "POST",
      "status": "failed",
      "failedAt": "2025-01-20T15:30:00Z",
      "attempts": 5,
      "lastError": {
        "code": 500,
        "message": "Internal Server Error",
        "responseTime": 30000
      },
      "originalBody": {
        "event": "user.created",
        "userId": "12345"
      },
      "createdAt": "2025-01-20T15:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 50,
    "totalPages": 3
  }
}

Getting a DLQ Message

Retrieve detailed information about a specific failed message:

curl https://api.anlyon.com/api/v2/dlq/msg_1234567890abcdef \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Response

{
  "success": true,
  "data": {
    "messageId": "msg_1234567890abcdef",
    "url": "https://example.com/webhook",
    "method": "POST",
    "status": "failed",
    "body": {
      "event": "user.created",
      "userId": "12345"
    },
    "headers": {},
    "createdAt": "2025-01-20T15:00:00Z",
    "scheduledFor": "2025-01-20T15:00:00Z",
    "failedAt": "2025-01-20T15:30:00Z",
    "attempts": 5,
    "maxRetries": 5,
    "retryHistory": [
      {
        "attempt": 1,
        "timestamp": "2025-01-20T15:00:00Z",
        "statusCode": 500,
        "error": "Internal Server Error",
        "responseTime": 30000
      },
      {
        "attempt": 2,
        "timestamp": "2025-01-20T15:00:02Z",
        "statusCode": 500,
        "error": "Internal Server Error",
        "responseTime": 30000
      }
    ],
    "lastError": {
      "code": 500,
      "message": "Internal Server Error",
      "responseTime": 30000,
      "responseBody": "{\"error\":\"Database connection failed\"}"
    }
  }
}

Retrying Failed Messages

Retry a Single Message

Retry a failed message immediately:

curl -X POST https://api.anlyon.com/api/v2/dlq/msg_1234567890abcdef/retry \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Response

{
  "success": true,
  "data": {
    "message": "Message queued for retry",
    "messageId": "msg_1234567890abcdef"
  }
}

Note: Retrying reuses the same message ID — the failed message returns to pending rather than becoming a new message. It is replayed with the environment and queue it was originally published under, so a halted environment and a paused queue still apply.

Batch Retry

Retry failed messages, up to 1000 per call:

curl -X POST https://api.anlyon.com/api/v2/dlq/retry-all \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Response

{
  "success": true,
  "data": {
    "message": "Messages queued for retry",
    "retriedCount": 3,
    "remaining": 0
  }
}

remaining is how many failed messages are left in this environment after the call. Call again while it is above zero.

Deleting DLQ Messages

Permanently remove a message from the DLQ:

curl -X DELETE https://api.anlyon.com/api/v2/dlq/msg_1234567890abcdef \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Warning: This action cannot be undone. The message will be permanently deleted.

DLQ Statistics

Get DLQ Summary

View summary statistics for failed messages:

curl https://api.anlyon.com/api/v2/dlq/stats \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Response

{
  "success": true,
  "data": {
    "total": 50,
    "last24Hours": 5,
    "last7Days": 20,
    "last30Days": 50,
    "byErrorCode": {
      "500": 30,
      "503": 10,
      "timeout": 5,
      "network": 5
    },
    "byUrl": [
      {
        "url": "https://example.com/webhook",
        "count": 25,
        "percentage": 50.0
      }
    ]
  }
}

Common Failure Scenarios

1. HTTP 500 Errors

Cause: Server-side errors in the destination endpoint

Solution:

  • Check destination server logs
  • Verify endpoint is operational
  • Retry after fixing the issue

2. Timeout Errors

Cause: Endpoint takes too long to respond

Solution:

  • Increase timeout in message configuration
  • Optimize destination endpoint performance
  • Consider async processing

3. Network Errors

Cause: Connection failures, DNS errors, SSL issues

Solution:

  • Verify endpoint URL is correct
  • Check network connectivity
  • Verify SSL certificates

4. HTTP 4xx Errors

Cause: Client errors (400, 401, 403, 404, etc.)

Solution:

  • Verify request format and authentication
  • Check endpoint URL and method
  • Review request headers and body

Code Examples

Using the official TypeScript SDK provides type safety and a cleaner API:

import { Client } from '@anlyonhq/sdk';

const client = new Client({
  apiKey: process.env.ANLYON_API_KEY!,
});

// List failed messages
const failed = await client.dlq.list({
  page: 1,
  limit: 20,
});

// Retry a single message
await client.dlq.retry('msg_1234567890abcdef');

// Batch retry
await client.dlq.retryBatch([
  'msg_1234567890abcdef',
  'msg_abcdef1234567890',
]);

// Get DLQ statistics
const stats = await client.dlq.getStats();
console.log(`Total failed: ${stats.data.total}`);

// Retry all transient errors
const dlq = await client.dlq.list();
for (const message of dlq.data) {
  if (message.lastError?.code >= 500 && message.lastError?.code < 600) {
    await client.dlq.retry(message.messageId);
  }
}

JavaScript/TypeScript (Raw Fetch)

async function getDLQMessages(page = 1, limit = 20) {
  const response = await fetch(
    `https://api.anlyon.com/api/v2/dlq?page=${page}&limit=${limit}`,
    {
      headers: {
        'Authorization': `Bearer ${process.env.ANLYON_API_KEY}`,
      },
    }
  );

  return response.json();
}

async function retryMessage(messageId: string) {
  const response = await fetch(
    `https://api.anlyon.com/api/v2/dlq/${messageId}/retry`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.ANLYON_API_KEY}`,
      },
    }
  );

  return response.json();
}

// Usage
const dlq = await getDLQMessages();
for (const message of dlq.data) {
  console.log(`Retrying ${message.messageId}...`);
  await retryMessage(message.messageId);
}

Python

import requests
import os

def get_dlq_messages(page=1, limit=20):
    response = requests.get(
        'https://api.anlyon.com/api/v2/dlq',
        headers={
            'Authorization': f'Bearer {os.getenv("ANLYON_API_KEY")}',
        },
        params={'page': page, 'limit': limit}
    )
    return response.json()

def retry_message(message_id):
    response = requests.post(
        f'https://api.anlyon.com/api/v2/dlq/{message_id}/retry',
        headers={
            'Authorization': f'Bearer {os.getenv("ANLYON_API_KEY")}',
        }
    )
    return response.json()

# Usage
dlq = get_dlq_messages()
for message in dlq['data']:
    print(f"Retrying {message['messageId']}...")
    retry_message(message['messageId'])

Monitoring DLQ

Set Up Alerts

Monitor DLQ size and set up alerts:

import { Client } from '@anlyonhq/sdk';

const client = new Client({
  apiKey: process.env.ANLYON_API_KEY!,
});

async function checkDLQSize() {
  const stats = await client.dlq.getStats();

  if (stats.data.total > 100) {
    // Send alert
    console.warn(`DLQ has ${stats.data.total} failed messages`);
  }
}

Automated Retry

Implement automated retry logic for transient failures:

async function autoRetryDLQ() {
  const dlq = await client.dlq.list();
  
  for (const message of dlq.data) {
    // Only retry if error is transient (5xx)
    if (message.lastError?.code >= 500 && message.lastError?.code < 600) {
      await client.dlq.retry(message.messageId);
    }
  }
}

Best Practices

  1. Monitor Regularly: Check DLQ size and failure patterns
  2. Investigate Root Causes: Analyze error patterns to fix underlying issues
  3. Set Up Alerts: Get notified when DLQ size exceeds thresholds
  4. Retry Strategically: Only retry after fixing the root cause
  5. Clean Up: Periodically delete old messages that won’t be retried
  6. Track Trends: Monitor failure rates to identify problems early
  7. Document Patterns: Keep notes on common failure scenarios

DLQ Retention

  • Messages are retained in DLQ for 30 days
  • After 30 days, messages are automatically deleted
  • Export important data before deletion
  • Use analytics to track long-term failure patterns

Next Steps

Was this page helpful?