class NatsBroker
implements MessageBrokerAdapter
Since 0.1.0

NATS JetStream message broker implementation.

Constructors

NatsBroker(
runtime: IRuntimeServices,
serializer: ISerializer,
options?: NatsOptions
)

Creates a new NATS broker.

Parameters
runtime: IRuntimeServices

Runtime services for uuid, timestamps, and timers

serializer: ISerializer

Serializer for message payloads

optional
options: NatsOptions

NATS connection and configuration options

Methods

Since 0.1.0
connect(): Promise<void>

Connects to NATS and ensures the JetStream stream exists.

Since 0.1.0
disconnect(): Promise<void>

Disconnects from NATS.

Since 0.1.0
isHealthy(): Promise<boolean>

Boolean port member (M70c): false only when positively unreachable.

Since 0.1.0
isReady(): boolean

Checks if the broker is connected.

Since 0.1.0
publish<T>(
topic: string,
message: T
): Promise<void>

Publishes a message to a subject (topic).

publishWithHeaders<T>(
topic: string,
message: T,
headers: Readonly<Record<string, string>>
): Promise<void>

Publishes a message with framework-owned transport headers. @internal

Since 0.1.0
reachability(): Promise<boolean | undefined>

Tri-state backend reachability (M70c).

nats reconnects itself, so the broker runs the supervisor in observe mode: Disconnect/Reconnect events mark the fault window, and the probe is isClosed() === false and rtt() resolving. true when both hold, false when the window is active or the connection reports closed, undefined when the injected client exposes neither member (a minimal fake) — the indicator then reports reachable: 'unknown'.

Since 0.1.0
request<TReq, TRes>(
topic: string,
message: TReq,
options?: RequestOptions
): Promise<TRes>

Sends a request and awaits a single correlated reply.

requestWithHeaders<TReq, TRes>(
topic: string,
message: TReq,
headers: Readonly<Record<string, string>>,
options?: RequestOptions
): Promise<TRes>

Sends request-reply traffic with framework-owned headers. @internal

Since 0.1.0
respond<TReq, TRes>(
topic: string,
handler: RequestHandler<TReq, TRes>,
): Promise<ISubscription>

Registers a responder whose result is returned to the requesting caller.

Since 0.1.0
subscribe<T>(
topic: string,
handler: MessageHandler<T>,
): Promise<ISubscription>

Subscribes to a topic using JetStream durable consumers.

subscribeWithHeaders<T>(
topic: string,
handler: MessageHandler<T>,
): Promise<ISubscription>

Subscribes through the header-aware internal path. @internal