Interface: BrokerWire
Defined in: packages/messaging/src/wire.ts:64
The broker, as this package uses it. A narrow port over a NATS connection, so the sender, the receiver and the publisher are tested against a fake and integration-tested against the real thing (natsWire).
Methods
drain()
drain():
Promise<void>
Defined in: packages/messaging/src/wire.ts:122
Finishes in-flight work and closes.
Returns
Promise<void>
isConnected()?
optionalisConnected():boolean
Defined in: packages/messaging/src/wire.ts:71
Whether the connection to the broker is known to be up. Optional: a wire that
cannot tell is treated as up, and a request on it waits out its own timeout. When
it returns false the sender fails the request at once with
broker.unavailable instead of waiting for a socket that is reconnecting.
Returns
boolean
publishPersistent()
publishPersistent(
subject,data,options):Promise<{duplicate:boolean;seq:number; }>
Defined in: packages/messaging/src/wire.ts:111
Publishes into JetStream and waits for the acknowledgement.
Parameters
subject
string
The concrete event subject.
data
Uint8Array
The payload bytes.
options
Headers, and msgId for Nats-Msg-Id de-duplication.
headers
Readonly<Record<string, string>>
msgId?
string
timeoutMs
number
Returns
Promise<{ duplicate: boolean; seq: number; }>
Whether the stream had already stored this msgId.
request()
request(
subject,data,options):Promise<WireResponse>
Defined in: packages/messaging/src/wire.ts:81
Sends a request and waits for one reply.
Parameters
subject
string
The concrete subject.
data
Uint8Array
The payload bytes.
options
Headers and how long to wait.
headers
Readonly<Record<string, string>>
timeoutMs
number
Returns
Promise<WireResponse>
Throws
No responder, timeout, or another transport failure.
subscribe()
subscribe(
subject,options,onMessage):WireSubscription
Defined in: packages/messaging/src/wire.ts:97
Subscribes. Handler failures are the handler's to catch; a throw is logged.
Parameters
subject
string
A subject, possibly with *.
options
The queue group, which for a module is the module's name.
queue
string
onMessage
(message) => Promise<void>
Called per message.