amqpx
v1.0.1
Published
Wrapper around amqplib with connection retries, topology definition, batching, and validation
Maintainers
Readme
amqpx
Type-safe RabbitMQ messaging for TypeScript, built on top of amqplib.
- Generic producers and consumers — define message shapes once, TypeScript enforces them everywhere
- Automatic reconnect — pluggable retry strategies handle broker failures transparently
- Composable topology — Connection → Channel → Exchange / Queue → Producer / Consumer
- Failure strategies — drop, requeue, or reject on handler errors, per consumer
- Batch consuming — built-in batching with configurable size, timeouts, and ack coalescing
- Extensions — optional Zod validation and in-memory test doubles for Vitest/Jest
Installation
npm install amqpx| Entry point | Contents |
|---|---|
| amqpx | Core entities |
| amqpx/zod | ZodValidatedConsumer, ZodValidatedBatchConsumer |
| amqpx/jest | Test doubles for Jest |
| amqpx/vitest | Test doubles for Vitest |
Quick example
import { connect, AssertionMode } from 'amqpx'
type Order = { orderId: string; total: number }
const connection = await connect({
hostname: 'localhost',
username: 'guest',
password: 'guest',
})
// Topology
const channel = await connection.createChannel()
const queue = await channel.createQueue('orders', { durable: true })
// Produce
const producer = await queue.createProducer<Order>()
await producer.publish({ orderId: 'abc-123', total: 49.99 })
// Consume
const consumer = await consumerQueue.createConsumer<Order>({ prefetch: 10 })
await consumer.listen(async ({ message }) => {
console.log('order', message.orderId, 'total', message.total)
})Documentation
Full documentation at https://patrikvalkovic.github.io/amqpx/
License
MIT
