Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

NatsConnection

import type { NatsConnection } from "https://raw.githubusercontent.com/nats-io/nats.deno/v1.27.0/nats-base-client/internal_mod.ts";
interface NatsConnection {
info?: ServerInfo;
services: ServicesAPI;
close(): Promise<void>;
closed(): Promise<void | Error>;
drain(): Promise<void>;
flush(): Promise<void>;
getServer(): string;
isClosed(): boolean;
isDraining(): boolean;
jetstream(opts?: JetStreamOptions | JetStreamManagerOptions): JetStreamClient;
jetstreamManager(opts?: JetStreamManagerOptions): Promise<JetStreamManager>;
publish(
subject: string,
payload?: Payload,
options?: PublishOptions,
): void;
publishMessage(msg: Msg): void;
reconnect(): Promise<void>;
request(
subject: string,
payload?: Payload,
): Promise<Msg>;
requestMany(
subject: string,
payload?: Payload,
opts?: Partial<RequestManyOptions>,
): Promise<AsyncIterable<Msg>>;
respondMessage(msg: Msg): boolean;
rtt(): Promise<number>;
stats(): Stats;
status(): AsyncIterable<Status>;
subscribe(subject: string, opts?: SubscriptionOptions): Subscription;
}

§Properties

§

ServerInfo to the currently connected server or undefined

§

Returns a ServicesAPI which allows you to build services using NATS.

§Methods

§
close(): Promise<void>
[src]

Close will close the connection to the server. This call will terminate all pending requests and subscriptions. The returned promise resolves when the connection closes.

§
closed(): Promise<void | Error>
[src]

Returns a promise that can be used to monitor if the client closes. The promise can resolve an Error if the reason for the close was an error. Note that the promise doesn't reject, but rather resolves to the error if there was one.

§
drain(): Promise<void>
[src]

Initiates a drain on the connection and returns a promise that resolves when the drain completes and the connection closes.

Drain is an ordered shutdown of the client. Instead of abruptly closing the client, subscriptions are drained, that is messages not yet processed by a subscription are handled before the subscription is closed. After subscriptions are drained it is not possible to create a new subscription. Then all pending outbound messages are sent to the server. Finally, the connection is closed.

§
flush(): Promise<void>
[src]

Returns a Promise that resolves when the client receives a reply from the server. Use of this API is not necessary by clients.

§
getServer(): string
[src]

Returns the hostport of the server the client is connected to.

§
isClosed(): boolean
[src]

Returns true if the client is closed.

§
isDraining(): boolean
[src]

Returns true if the client is draining.

§
jetstream(opts?: JetStreamOptions | JetStreamManagerOptions): JetStreamClient
[src]

Returns a {@link JetStreamClient} which allows publishing messages to JetStream or consuming messages from streams.

@param opts
§
jetstreamManager(opts?: JetStreamManagerOptions): Promise<JetStreamManager>
[src]

Returns a Promise to a {@link JetStreamManager} which allows the client to access Streams and Consumers information.

@param opts
§
publish(
subject: string,
payload?: Payload,
options?: PublishOptions,
): void
[src]

Publishes the specified data to the specified subject.

@param subject
@param payload
@param options
§
publishMessage(msg: Msg): void
[src]

Publishes using the subject of the specified message, specifying the data, headers and reply found in the message if any.

@param msg
§
reconnect(): Promise<void>
[src]

Use of this API is experimental, and it is subject to be removed.

reconnect() enables a client to force a reconnect. A reconnect will disconnect the client, and possibly initiate a reconnect to the cluster. Note that all reconnect caveats apply:

  • If the reconnection policy given to the client doesn't allow reconnects, the connection will close.

  • Messages that are inbound or outbound could be lost.

  • All requests that are in flight will be rejected.

Note that the returned promise will reject if the client is already closed, or if it is in the process of draining. If the client is currently disconnected, this API has no effect, as the client is already attempting to reconnect.

§
request(
subject: string,
payload?: Payload,
): Promise<Msg>
[src]

Publishes a request with specified data in the specified subject expecting a response before {@link RequestOptions#timeout} milliseconds. The api returns a Promise that resolves when the first response to the request is received. If there are no responders (a subscription) listening on the request subject, the request will fail as soon as the server processes it.

@param subject
@param payload
@param opts
§
requestMany(
subject: string,
payload?: Payload,
opts?: Partial<RequestManyOptions>,
): Promise<AsyncIterable<Msg>>
[src]

Publishes a request expecting multiple responses back. Several strategies to determine when the request should stop gathering responses.

@param subject
@param payload
@param opts
§
respondMessage(msg: Msg): boolean
[src]

Replies using the reply subject of the specified message, specifying the data, headers in the message if any.

@param msg
§
rtt(): Promise<number>
[src]
@return

the number of milliseconds it took for a {@link flush}.

§
stats(): Stats
[src]

Returns some metrics such as the number of messages and bytes sent and recieved by the client.

§
status(): AsyncIterable<Status>
[src]

Returns an async iterator of Status that may be useful in understanding when the client looses a connection, or reconnects, or receives an update from the cluster among other things.

@return

an AsyncIterable

§
subscribe(subject: string, opts?: SubscriptionOptions): Subscription
[src]

Subscribe expresses interest in the specified subject. The subject may have wildcards. Messages are delivered to the {@link SubOpts#callback | SubscriptionOptions callback} if specified. Otherwise, the subscription is an async iterator for Msg.

@param subject
@param opts