Closes the connection and ends every subscription.
Resolves once the socket is closed.
Returns a JetStreamManager bound to this connection for durable streaming.
JetStream layers a JSON request-reply protocol over the same socket, so the manager simply
reuses this connection's publish/request. The server must have JetStream enabled (-js).
A JetStream context for ensuring streams, publishing with PubAcks, and durable pulls.
Publishes a message to a subject.
The subject to publish to.
Optionaldata: string | Uint8Array<ArrayBufferLike>
The payload (string is UTF-8 encoded); empty if omitted.
Optionalopts: { reply?: string }
Optional reply subject for request-reply.
Resolves once the PUB frame is written.
Publishes a value as JSON to a subject.
The value is JSON.stringify-ed and encoded as UTF-8, then published with publish.
The subject to publish to.
The value to serialize and publish.
Optionalopts: { reply?: string }
Optional reply subject for request-reply.
Resolves once the PUB frame is written.
Sends a request and waits for the first reply on a private inbox.
The subject to send the request to.
Optionaldata: string | Uint8Array<ArrayBufferLike>
The request payload (string is UTF-8 encoded).
Optionalopts: { timeoutMs?: number }
Optional per-request timeout (defaults to 2000ms).
The first reply message.
Sends a JSON request and parses the reply payload as JSON.
Serializes value with JSON.stringify, sends it via request, then UTF-8 decodes
and JSON.parses the reply.
The expected shape of the decoded reply.
The subject to send the request to.
The request value to serialize.
Optionalopts: { timeoutMs?: number }
Optional per-request timeout (defaults to 2000ms).
The parsed reply value.
Subscribes to a subject, optionally as part of a queue group.
The subject (may contain * / > wildcards).
Optionalopts: { queue?: string }
Optional queue group name for load-balanced delivery.
A subscription whose async iterator yields matching messages.
Subscribes to a subject and yields each message with its payload parsed from JSON.
A thin JSON layer over subscribe: each delivered message's payload is UTF-8 decoded
and JSON.parse-d. Iterate the result with for await. It is an AsyncDisposable, so
await using unsubscribes automatically.
The expected shape of each decoded value.
The subject (may contain * / > wildcards).
Optionalopts: { queue?: string }
Optional queue group name for load-balanced delivery.
An async iterable of { subject, reply?, value }, also an AsyncDisposable.
A live NATS connection over a single socket.
Obtain one from connect. A background pump reads the socket and routes messages, so publishing, subscribing, and requesting can all be in flight at once. It is an
AsyncDisposable, soawait usingcloses it cleanly.Since
1.0.0