@pg-prime/mq
v0.2.4
Published
Work queues on PostgreSQL for pg-prime: leases, retries, priorities, groups, flows and topic bindings. Pre-alpha — the API will change.
Maintainers
Readme
@pg-prime/mq
Work queues on PostgreSQL for pg-prime: competing consumers with a lease and a token, retries with backoff, delay, priority, dedup, groups, global limits, flows, a dead-letter state, and topic → queue bindings.
Status: pre-alpha. The API may change before 1.0.
import { defineQueue, pgMq } from '@pg-prime/mq'
const emails = defineQueue<{ to: string }>('emails')
const mq = pgMq({ db, define: { emails } })
await mq.start()
await db.transaction(async (tx) => {
// …your writes…
await mq.queues.emails.send({ to: '[email protected]' }, { tx })
})
mq.queues.emails.work(async (m) => sendEmail(m.payload.to), { concurrency: 10 })- Transactional. A send joins your transaction;
ctx.transaction(fn)commits your writes and the completion together. - Safe under concurrency. Claims use
SKIP LOCKED; every consumer write is guarded by its token; an expired lease is one failed attempt, recovered once. - One dependency.
@pg-prime/eventsprovides wake-ups and bindings;pg-primeis the peer. - PostgreSQL 15–18, PgBouncer transaction mode (by polling), Node and Bun.
Docs: guide · concepts · operations · reference.
