The resurgence of PostgreSQL as a robust message queue platform has gained momentum with extensions like pgmq, which enables lightweight queueing directly within Postgres databases. This approach is particularly appealing for teams using Supabase or self-managed Postgres instances seeking to minimize infrastructure complexity. However, developer Tiago Santos identified a critical gap: no Node.js library existed to handle message consumption, processing workflows, and error handling for pgmq implementations.

Santos' solution—consumer-pgmq—fills this void with an elegant Node.js module that abstracts message polling and processing. The standout feature? Configurable dead letter queue (DLQ) support, a reliability mechanism essential for production systems. Here's how it works:

const { Consumer } = require('consumer-pgmq');

const consumer = new Consumer({
  connection: { /* Postgres config */ },
  queue: 'tasks',
  maxAttempts: 2, // Retry twice before DLQ
  handler: async (msg) => {
    if (msg.body.shouldFail) throw new Error('Processing failed!');
    return { status: 'success' };
  }
});

consumer.start();

When a message processing attempt fails, the module automatically:
1. Retries according to maxAttempts (e.g., 2 retries)
2. On final failure, moves the message to a dedicated _dlq suffix queue (e.g., tasks_dlq)
3. Preserves original message metadata for debugging

"This moves PostgreSQL queues closer to feature parity with dedicated systems like RabbitMQ," observes Santos. "Developers get transactional safety from Postgres plus essential resilience patterns without new infrastructure."

The implementation addresses two pain points in message-driven architectures:
- Poison pill messages: Malformed payloads no longer indefinitely block queues
- Transient failure recovery: Network blips or temporary dependencies won't cause permanent data loss

While pgmq itself provides basic queue operations, consumer-pgmq introduces crucial semantics for real-world applications:
- At-least-once delivery guarantees
- Backoff strategies for retries
- Visibility into failed messages via DLQ inspection

Santos' module is open-sourced on GitHub and available via npm. For teams standardizing on Postgres for application infrastructure, this eliminates a significant barrier to adopting database-native message queues in Node.js microservices.

The convergence of PostgreSQL's reliability with modern queueing patterns signals a shift: increasingly, developers are choosing transactional databases over specialized brokers for simplicity. With tools like consumer-pgmq, that choice doesn't require sacrificing essential messaging safeguards.