Table of Contents

Class NatsConnection

Namespace
NATS.Client.Core
Assembly
NATS.Client.Core.dll
public class NatsConnection : INatsConnection, INatsClient, IAsyncDisposable
Inheritance
NatsConnection
Implements
Inherited Members
Extension Methods

Constructors

NatsConnection()
NatsConnection(NatsOpts)

Fields

OnConnectingAsync

Hook before TCP connection open.

Properties

Connection

Represents a connection to the NATS server.

ConnectionState

Connection state of the NATS connection.

HeaderParser

Singleton instance of the NATS header parser used to parse message headers used by the NATS connection.

Opts

Options used to configure the NATS connection.

ServerInfo

Server information received from the NATS server.

SubscriptionManager

Subscription manager used to manage subscriptions for the NATS connection.

Methods

AddSubAsync(NatsSubBase, CancellationToken)

Adds a subscription to the NATS connection for a given NatsSubBase object. Subscriptions are managed by the connection and are automatically removed when the connection is closed.

ConnectAsync()

Connect socket and write CONNECT command to nats server.

CreateRequestSubAsync<TRequest, TReply>(string, TRequest?, NatsHeaders?, INatsSerialize<TRequest>?, INatsDeserialize<TReply>?, NatsPubOpts?, NatsSubOpts?, CancellationToken)

Creates a subscription with appropriate request and reply subjects publishing the request. It's the caller's responsibility to retrieve the reply messages and complete the subscription.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

GetBoundedChannelOpts(NatsSubChannelOpts?)

Retrieves the bounded channel options for creating a channel used by a subscription. Options are built from the connection's configuration and the subscription channel options. Used to aid in custom message handling when building a subscription channel.

NewInbox()

Create a new inbox subject with the form {Inbox Prefix}.{Unique Connection ID}.{Unique Inbox ID}

OnMessageDropped<T>(NatsSubBase, int, NatsMsg<T>)

Called when a message is dropped for a subscription. Used to aid in custom message handling when a subscription's message channel is full.

PingAsync(CancellationToken)

Send PING command and await PONG. Return value is similar as Round Trip Time (RTT).

PublishAsync(string, NatsHeaders?, string?, NatsPubOpts?, CancellationToken)

Publishes an empty message payload to the given subject name, optionally supplying a reply subject.

PublishAsync<T>(in NatsMsg<T>, INatsSerialize<T>?, NatsPubOpts?, CancellationToken)

Publishes a serializable message payload to the given subject name, optionally supplying a reply subject.

PublishAsync<T>(string, T?, NatsHeaders?, string?, INatsSerialize<T>?, NatsPubOpts?, CancellationToken)

Publishes a serializable message payload to the given subject name, optionally supplying a reply subject.

RequestAsync<TReply>(string, INatsDeserialize<TReply>?, NatsSubOpts?, CancellationToken)

Send an empty request message and await the reply message asynchronously.

RequestAsync<TRequest, TReply>(string, TRequest?, NatsHeaders?, INatsSerialize<TRequest>?, INatsDeserialize<TReply>?, NatsPubOpts?, NatsSubOpts?, CancellationToken)

Request and receive a single reply from a responder.

RequestManyAsync<TRequest, TReply>(string, TRequest?, NatsHeaders?, INatsSerialize<TRequest>?, INatsDeserialize<TReply>?, NatsPubOpts?, NatsSubOpts?, CancellationToken)

Request and receive zero or more replies from a responder.

SubscribeAsync<T>(string, string?, INatsDeserialize<T>?, NatsSubOpts?, CancellationToken)

Initiates a subscription to a subject, optionally joining a distributed queue group.

SubscribeCoreAsync<T>(string, string?, INatsDeserialize<T>?, NatsSubOpts?, CancellationToken)

Initiates a subscription to a subject, optionally joining a distributed queue group and returns a INatsSub<T> object which provides more control over the subscription.

Events

ConnectionDisconnected

Event that is raised when the connection to the NATS server is disconnected.

ConnectionOpened

Event that is raised when the connection to the NATS server is opened.

MessageDropped

Event that is raised when a message is dropped for a subscription.

ReconnectFailed

Event that is raised when a reconnect attempt is failed.