@equinox-js/message-db-source
The @equinox-js/message-db-source
library provides a convenient API for consuming events from a MessageDB instance.
It's designed to be used with equinox-js projects but can be used in any node application.
Features
- High throughput message consumption
- Integrated checkpointer for resuming from last processed event
- Configurable batch sizes for event fetching
- Support for handling multiple concurrent streams
- Automatic reconnection and backoff
import { MessageDbSource, PgCheckpoints } from "@equinox-js/message-db-source"
import pg from "pg"
const checkpointer = new PgCheckpoints(new pg.Pool({ connectionString: "..." }), "public")
await checkpointer.ensureTable()
const pool = new pg.Pool({ connectionString: "..." })
const source = MessageDbSource.create({
pool,
batchSize: 500,
categories: ["Invoice"],
groupName: "InvoiceAutoEmailer",
checkpointer,
handler: async (streamName, events) =>
console.log("received", events.length, "events for", streamName),
tailSleepIntervalMs: 100,
maxConcurrentStreams: 10,
})
const ctrl = new AbortController()
source.start(ctrl.signal)