@nwire/bus-nats
v0.7.1
Published
Nwire — NATS-backed EventBus adapter. Core pub/sub by default; JetStream-ready (consumer-side durability is opt-in via NATS connection options).
Readme
@nwire/bus-nats
NATS-backed
EventBus— production cross-service pub/sub.
What it does
Wraps a NATS connection to satisfy the @nwire/bus EventBus contract. Subject layout is <prefix>.<eventName>; prefix isolates one deployment from another on the same cluster. Defaults to NATS core pub/sub (at-most-once, fan-out); switch to JetStream for at-least-once durability without contract changes.
Install
pnpm add @nwire/bus-nats natsQuick start
import { connect } from "nats";
import { NatsEventBus } from "@nwire/bus-nats";
import { lxApp } from "@amit/lx";
const nc = await connect({ servers: "nats://nats:4222" });
const bus = new NatsEventBus({ connection: nc, prefix: "lemida" });
const app = lxApp.create({ bus, publishToBus: true, appName: "lx-service" });
await app.start();API surface
NatsEventBus({ connection, prefix? })— implementsEventBus.NatsConnectionLike— minimal connection contract (accepts classicnatsor@nats-io/transport-node).
When to use
When deploying as multiple services on a shared NATS cluster.
Within nwire-app
For developers using this package as part of the Nwire stack — register it via app.use(...) or it auto-wires when you compose createApp({ modules }).
import { createApp } from "@nwire/forge";
const app = createApp({
/* ...config... */
});
// Adapter/plugin wiring happens here when applicable.