@nwire/bus
v0.16.1
Published
Nwire — cross-service event bus contract. EventBus interface + InMemoryEventBus default. Production adapters land as @nwire/nats, @nwire/bus-redis, @nwire/bus-kafka.
Readme
@nwire/bus
Cross-service event bus contract — pub/sub for events that leave one service and reach another.
What it does
Defines EventBus, the publish-subscribe contract used to fan domain events across deployable services. Within one service the runtime fans events to in-process actors/projections/reactions; across services those same events flow through this bus (NATS in production, in-memory in tests). Ships InMemoryEventBus for dev/tests; swap in @nwire/nats (or any other adapter) by config.
Install
pnpm add @nwire/busQuick start
import { InMemoryEventBus } from "@nwire/bus";
import { createApp } from "@nwire/app";
import { forgePlugins } from "@nwire/forge";
const bus = new InMemoryEventBus();
const app = createApp({
appName: "learnflow",
plugins: [...forgePlugins({ bus })],
});
await app.start();
// `.public()` events now drain to the bus; cross-service subscribers can react.Wiring a bus installs it as the runtime's outbound terminal sink stage — every ctx.publish of a .public() event drains through the runtime's one sink chain and reaches bus.publish exactly once, stamped with the originating app as origin. No bus wired = publish stays local. Outside forge, install the stage directly:
runtime.sink(busSinkStage(bus, { origin: runtime.appName }));API surface
EventBus—publish(message)+subscribe(eventName, handler) => unsubscribe.InMemoryEventBus— in-process default for tests / single-service deployments.busSinkStage(bus, { origin })— the bus as a terminal sink stage forruntime.sink(...).BusEventMessage/BusSubscriber— wire types.
When to use
When the system is deployed as more than one process (split services, microservices).
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.