NATS .NET Client  1.1.4
The NATS.io .NET C# Client
NATS.Client.Connection Class Reference
Inheritance diagram for NATS.Client.Connection:
NATS.Client.IConnection NATS.Client.EncodedConnection

Classes

class  TCPConnection
 

Public Member Functions

void Publish (string subject, byte[] data)
 
void Publish (string subject, MsgHeader headers, byte[] data)
 
void Publish (string subject, byte[] data, int offset, int count)
 
void Publish (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
void Publish (string subject, string reply, byte[] data)
 
void Publish (string subject, string reply, MsgHeader headers, byte[] data)
 
void Publish (string subject, string reply, byte[] data, int offset, int count)
 
void Publish (string subject, string reply, MsgHeader headers, byte[] data, int offset, int count)
 
void Publish (Msg msg)
 
Msg Request (string subject, byte[] data, int timeout)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int timeout)
 
Msg Request (string subject, byte[] data, int offset, int count, int timeout)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int offset, int count, int timeout)
 
Msg Request (string subject, byte[] data)
 
Msg Request (string subject, MsgHeader headers, byte[] data)
 
Msg Request (string subject, byte[] data, int offset, int count)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
Msg Request (Msg message, int timeout)
 
Msg Request (Msg message)
 
Task< MsgRequestAsync (string subject, byte[] data, int timeout)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int timeout)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count, int timeout)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count, int timeout)
 
Task< MsgRequestAsync (string subject, byte[] data)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
Task< MsgRequestAsync (string subject, byte[] data, int timeout, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int timeout, CancellationToken token)
 
Task< MsgRequestAsync (string subject, byte[] data, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, CancellationToken token)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count, CancellationToken token)
 
Task< MsgRequestAsync (Msg message, int timeout)
 
Task< MsgRequestAsync (Msg message)
 
Task< MsgRequestAsync (Msg message, int timeout, CancellationToken token)
 
Task< MsgRequestAsync (Msg message, CancellationToken token)
 
string NewInbox ()
 
ISyncSubscription SubscribeSync (string subject)
 
IAsyncSubscription SubscribeAsync (string subject)
 
IAsyncSubscription SubscribeAsync (string subject, EventHandler< MsgHandlerEventArgs > handler)
 
ISyncSubscription SubscribeSync (string subject, string queue)
 
IAsyncSubscription SubscribeAsync (string subject, string queue)
 
IAsyncSubscription SubscribeAsync (string subject, string queue, EventHandler< MsgHandlerEventArgs > handler)
 
void Flush (int timeout)
 
TimeSpan RTT ()
 
void Flush ()
 
void FlushBuffer ()
 
void Close ()
 
bool IsClosed ()
 
void Drain ()
 
void Drain (int timeout)
 
Task DrainAsync ()
 
Task DrainAsync (int timeout)
 
bool IsDraining ()
 
bool IsReconnecting ()
 
void ResetStats ()
 
override string ToString ()
 
void Dispose ()
 
IStreamContext GetStreamContext (string streamName)
 
IStreamContext GetStreamContext (string streamName, JetStreamOptions options)
 
IConsumerContext GetConsumerContext (string streamName, string consumerName)
 
IConsumerContext GetConsumerContext (string streamName, string consumerName, JetStreamOptions options)
 
IJetStream CreateJetStreamContext (JetStreamOptions options=null)
 
IJetStreamManagement CreateJetStreamManagementContext (JetStreamOptions options=null)
 
IKeyValue CreateKeyValueContext (string bucketName, KeyValueOptions options=null)
 
IKeyValueManagement CreateKeyValueManagementContext (KeyValueOptions options=null)
 
IObjectStore CreateObjectStoreContext (string bucketName, ObjectStoreOptions options=null)
 
IObjectStoreManagement CreateObjectStoreManagementContext (ObjectStoreOptions options=null)
 
void Publish (string subject, byte[] data)
 
void Publish (string subject, MsgHeader headers, byte[] data)
 
void Publish (string subject, byte[] data, int offset, int count)
 
void Publish (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
void Publish (string subject, string reply, byte[] data)
 
void Publish (string subject, string reply, MsgHeader headers, byte[] data)
 
void Publish (string subject, string reply, byte[] data, int offset, int count)
 
void Publish (string subject, string reply, MsgHeader headers, byte[] data, int offset, int count)
 
void Publish (Msg msg)
 
Msg Request (string subject, byte[] data, int timeout)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int timeout)
 
Msg Request (string subject, byte[] data, int offset, int count, int timeout)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int offset, int count, int timeout)
 
Msg Request (string subject, byte[] data)
 
Msg Request (string subject, MsgHeader headers, byte[] data)
 
Msg Request (string subject, byte[] data, int offset, int count)
 
Msg Request (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
Msg Request (Msg message)
 
Msg Request (Msg message, int timeout)
 
Task< MsgRequestAsync (string subject, byte[] data, int timeout)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int timeout)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count, int timeout)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count, int timeout)
 
Task< MsgRequestAsync (string subject, byte[] data)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count)
 
Task< MsgRequestAsync (string subject, byte[] data, int timeout, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int timeout, CancellationToken token)
 
Task< MsgRequestAsync (string subject, byte[] data, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, CancellationToken token)
 
Task< MsgRequestAsync (string subject, byte[] data, int offset, int count, CancellationToken token)
 
Task< MsgRequestAsync (string subject, MsgHeader headers, byte[] data, int offset, int count, CancellationToken token)
 
Task< MsgRequestAsync (Msg message)
 
Task< MsgRequestAsync (Msg message, int timeout)
 
Task< MsgRequestAsync (Msg message, CancellationToken token)
 
Task< MsgRequestAsync (Msg message, int timeout, CancellationToken token)
 
string NewInbox ()
 
ISyncSubscription SubscribeSync (string subject)
 
IAsyncSubscription SubscribeAsync (string subject)
 
IAsyncSubscription SubscribeAsync (string subject, EventHandler< MsgHandlerEventArgs > handler)
 
ISyncSubscription SubscribeSync (string subject, string queue)
 
IAsyncSubscription SubscribeAsync (string subject, string queue)
 
IAsyncSubscription SubscribeAsync (string subject, string queue, EventHandler< MsgHandlerEventArgs > handler)
 
void Flush (int timeout)
 
TimeSpan RTT ()
 
void Flush ()
 
void FlushBuffer ()
 
void Close ()
 
bool IsClosed ()
 
bool IsReconnecting ()
 
void ResetStats ()
 
Task DrainAsync ()
 
Task DrainAsync (int timeout)
 
void Drain ()
 
void Drain (int timeout)
 
bool IsDraining ()
 
IStreamContext GetStreamContext (string streamName)
 
IStreamContext GetStreamContext (string streamName, JetStreamOptions options)
 
IConsumerContext GetConsumerContext (string streamName, string consumerName)
 
IConsumerContext GetConsumerContext (string streamName, string consumerName, JetStreamOptions options)
 
IJetStream CreateJetStreamContext (JetStreamOptions options=null)
 
IJetStreamManagement CreateJetStreamManagementContext (JetStreamOptions options=null)
 
IKeyValue CreateKeyValueContext (string bucketName, KeyValueOptions options=null)
 
IKeyValueManagement CreateKeyValueManagementContext (KeyValueOptions options=null)
 
IObjectStore CreateObjectStoreContext (string bucketName, ObjectStoreOptions options=null)
 
IObjectStoreManagement CreateObjectStoreManagementContext (ObjectStoreOptions options=null)
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Properties

Options Opts [get]
 
string ConnectedUrl [get]
 
IPAddress ClientIP [get]
 
int ClientID [get]
 
string ConnectedId [get]
 
ServerInfo ServerInfo [get]
 
string[] Servers [get]
 
string[] DiscoveredServers [get]
 
Exception LastError [get]
 
ConnState State [get]
 
int SubscriptionCount [get]
 
IStatistics Stats [get]
 
long MaxPayload [get]
 
- Properties inherited from NATS.Client.IConnection
Options Opts [get]
 
IPAddress ClientIP [get]
 
int ClientID [get]
 
string ConnectedUrl [get]
 
string ConnectedId [get]
 
ServerInfo ServerInfo [get]
 
string[] Servers [get]
 
string[] DiscoveredServers [get]
 
Exception LastError [get]
 
ConnState State [get]
 
IStatistics Stats [get]
 
long MaxPayload [get]
 
int SubscriptionCount [get]
 

Detailed Description

Connection represents a bare connection to a NATS server. Users should create an IConnection instance using ConnectionFactory rather than directly using this class.

Member Function Documentation

◆ Close()

void NATS.Client.Connection.Close ( )

Closes the Connection and all associated subscriptions.

See also
IsClosed, State

Implements NATS.Client.IConnection.

◆ CreateJetStreamContext()

IJetStream NATS.Client.Connection.CreateJetStreamContext ( JetStreamOptions  options = null)

Gets a context for publishing and subscribing to subjects backed by Jetstream streams and consumers.

Parameters
optionsOptional JetStream options.
Returns

Implements NATS.Client.IConnection.

◆ CreateJetStreamManagementContext()

IJetStreamManagement NATS.Client.Connection.CreateJetStreamManagementContext ( JetStreamOptions  options = null)

Gets a context for administrating JetStream.

Parameters
optionsOptional JetStream options.
Returns
an IJetStreamManagement instance

Implements NATS.Client.IConnection.

◆ CreateKeyValueContext()

IKeyValue NATS.Client.Connection.CreateKeyValueContext ( string  bucketName,
KeyValueOptions  options = null 
)

Gets a context for a Key Value bucket

Parameters
bucketNameThe name of the bucket
optionsOptional KeyValueOptions.
Returns

Implements NATS.Client.IConnection.

◆ CreateKeyValueManagementContext()

IKeyValueManagement NATS.Client.Connection.CreateKeyValueManagementContext ( KeyValueOptions  options = null)

Gets a context for administrating Key Value buckets

Parameters
optionsOptional KeyValueOptions.
Returns

Implements NATS.Client.IConnection.

◆ CreateObjectStoreContext()

IObjectStore NATS.Client.Connection.CreateObjectStoreContext ( string  bucketName,
ObjectStoreOptions  options = null 
)

Gets a context for a Object Store OBJECT STORE IMPLEMENTATION IS EXPERIMENTAL AND SUBJECT TO CHANGE.

Parameters
bucketNameThe name of the bucket
optionsOptional ObjectStoreOptions.
Returns

Implements NATS.Client.IConnection.

◆ CreateObjectStoreManagementContext()

IObjectStoreManagement NATS.Client.Connection.CreateObjectStoreManagementContext ( ObjectStoreOptions  options = null)

Gets a context for administrating Object Stores OBJECT STORE IMPLEMENTATION IS EXPERIMENTAL AND SUBJECT TO CHANGE.

Parameters
optionsOptional ObjectStoreOptions.
Returns

Implements NATS.Client.IConnection.

◆ Dispose() [1/2]

void NATS.Client.Connection.Dispose ( )

Releases all resources used by the Connection.

This method disposes the connection, by clearing all pending operations, and closing the connection to release resources.

◆ Dispose() [2/2]

virtual void NATS.Client.Connection.Dispose ( bool  disposing)
protectedvirtual

Closes the connection and optionally releases the managed resources.

In derived classes, do not override the Close method, instead put all of the

See also
Connection

cleanup logic in your Dispose override.

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Reimplemented in NATS.Client.EncodedConnection.

◆ Drain() [1/2]

void NATS.Client.Connection.Drain ( )

Drains a connection for graceful shutdown.

Drain will put a connection into a drain state. All subscriptions will immediately be put into a drain state. Upon completion, the publishers will be drained and can not publish any additional messages. Upon draining of the publishers, the connection will be closed. Use the Options.ClosedEventHandler option to know when the connection has moved from draining to closed.

See also
Close()

Implements NATS.Client.IConnection.

◆ Drain() [2/2]

void NATS.Client.Connection.Drain ( int  timeout)

Drains a connection for graceful shutdown.

Drain will put a connection into a drain state. All subscriptions will immediately be put into a drain state. Upon completion, the publishers will be drained and can not publish any additional messages. Upon draining of the publishers, the connection will be closed. Use the Options.ClosedEventHandler option to know when the connection has moved from draining to closed.

See also
Close()
Parameters
timeoutThe duration to wait before draining.


Implements NATS.Client.IConnection.

◆ DrainAsync() [1/2]

Task NATS.Client.Connection.DrainAsync ( )

Drains a connection for graceful shutdown.

Drain will put a connection into a drain state. All subscriptions will immediately be put into a drain state. Upon completion, the publishers will be drained and can not publish any additional messages. Upon draining of the publishers, the connection will be closed. Use the Options.ClosedEventHandler option to know when the connection has moved from draining to closed.

See also
Close()
Returns
A task that represents the asynchronous drain operation.

Implements NATS.Client.IConnection.

◆ DrainAsync() [2/2]

Task NATS.Client.Connection.DrainAsync ( int  timeout)

Drains a connection for graceful shutdown.

Drain will put a connection into a drain state. All subscriptions will immediately be put into a drain state. Upon completion, the publishers will be drained and can not publish any additional messages. Upon draining of the publishers, the connection will be closed. Use the Options.ClosedEventHandler option to know when the connection has moved from draining to closed.

See also
Close()
Parameters
timeoutThe duration to wait before draining.
Returns
A task that represents the asynchronous drain operation.

Implements NATS.Client.IConnection.

◆ Flush() [1/2]

void NATS.Client.Connection.Flush ( )

Performs a round trip to the server and returns when it receives the internal reply.

Exceptions
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Flush() [2/2]

void NATS.Client.Connection.Flush ( int  timeout)

Performs a round trip to the server and returns when it receives the internal reply, or throws a NATSTimeoutException exception if the NATS Server does not reply in time.

Parameters
timeoutThe number of milliseconds to wait.
Exceptions
ArgumentOutOfRangeExceptiontimeout is less than or equal to zero (0).
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ FlushBuffer()

void NATS.Client.Connection.FlushBuffer ( )

Immediately flushes the underlying connection buffer if the connection is valid.

Exceptions
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.

Implements NATS.Client.IConnection.

◆ GetConsumerContext() [1/2]

IConsumerContext NATS.Client.Connection.GetConsumerContext ( string  streamName,
string  consumerName 
)

Get a consumer context for a specific named stream and specific named consumer. Verifies that the stream and consumer exist.

Parameters
streamNamethe name of the stream
consumerNamethe name of the consumer
Returns
an IConsumerContext instance

Implements NATS.Client.IConnection.

◆ GetConsumerContext() [2/2]

IConsumerContext NATS.Client.Connection.GetConsumerContext ( string  streamName,
string  consumerName,
JetStreamOptions  options 
)

Get a consumer context for a specific named stream and specific named consumer. Verifies that the stream and consumer exist.

Parameters
streamNamethe name of the stream
consumerNamethe name of the consumer
optionsJetStream options.
Returns
an IConsumerContext instance

Implements NATS.Client.IConnection.

◆ GetStreamContext() [1/2]

IStreamContext NATS.Client.Connection.GetStreamContext ( string  streamName)

Get a stream context for a specific stream.

Parameters
streamNamethe stream for the context
Returns

a StreamContext instance.

an IStreamContext instance

Implements NATS.Client.IConnection.

◆ GetStreamContext() [2/2]

IStreamContext NATS.Client.Connection.GetStreamContext ( string  streamName,
JetStreamOptions  options 
)

Gets a stream context.

Parameters
streamNamethe stream for the context
optionsJetStream options.
Returns
an IStreamContext instance

Implements NATS.Client.IConnection.

◆ IsClosed()

bool NATS.Client.Connection.IsClosed ( )

Returns a value indicating whether or not the Connection instance is closed.

Returns
true if and only if the Connection is closed, otherwise false.
See also
Close, State

Implements NATS.Client.IConnection.

◆ IsDraining()

bool NATS.Client.Connection.IsDraining ( )

Returns a value indicating whether or not the Connection instance is draining.

Returns
true if and only if the Connection is draining, otherwise false.
See also
IConnection.Drain(), State

Implements NATS.Client.IConnection.

◆ IsReconnecting()

bool NATS.Client.Connection.IsReconnecting ( )

Returns a value indicating whether or not the Connection is currently reconnecting.

Returns
true if and only if the Connection is reconnecting, otherwise false.
See also
State

Implements NATS.Client.IConnection.

◆ NewInbox()

string NATS.Client.Connection.NewInbox ( )

Creates an inbox string which can be used for directed replies from subscribers.

The returned inboxes are guaranteed to be unique, but can be shared and subscribed to by others.

Returns
A unique inbox string.

Implements NATS.Client.IConnection.

◆ Publish() [1/9]

void NATS.Client.Connection.Publish ( Msg  msg)

Publishes a Msg instance, which includes the subject, an optional reply, and an optional data field.

Parameters
msgA Msg instance containing the subject, optional reply, and data to publish to the NATS server.
Exceptions
ArgumentNullExceptionmsg is null.
NATSBadSubscriptionExceptionThe Msg.Subject property of msg is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while publishing. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Publish() [2/9]

void NATS.Client.Connection.Publish ( string  subject,
byte[]  data 
)

Publishes data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while publishing. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Publish() [3/9]

void NATS.Client.Connection.Publish ( string  subject,
byte[]  data,
int  offset,
int  count 
)

Publishes a sequence of bytes from data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
See also
IConnection.Publish(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Publish() [4/9]

void NATS.Client.Connection.Publish ( string  subject,
MsgHeader  headers,
byte[]  data 
)

Publishes data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while publishing. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Publish() [5/9]

void NATS.Client.Connection.Publish ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count 
)

Publishes a sequence of bytes from data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
See also
IConnection.Publish(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Publish() [6/9]

void NATS.Client.Connection.Publish ( string  subject,
string  reply,
byte[]  data 
)

Publishes data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
replyAn optional reply subject.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while publishing. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Publish() [7/9]

void NATS.Client.Connection.Publish ( string  subject,
string  reply,
byte[]  data,
int  offset,
int  count 
)

Publishes a sequence of bytes from data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
replyAn optional reply subject.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
See also
IConnection.Publish(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Publish() [8/9]

void NATS.Client.Connection.Publish ( string  subject,
string  reply,
MsgHeader  headers,
byte[]  data 
)

Publishes data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
replyAn optional reply subject.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSExceptionThere was an unexpected exception performing an internal NATS call while publishing. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Publish() [9/9]

void NATS.Client.Connection.Publish ( string  subject,
string  reply,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count 
)

Publishes a sequence of bytes from data to the given subject .

Parameters
subjectThe subject to publish data to over the current connection.
replyAn optional reply subject.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
See also
IConnection.Publish(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Request() [1/10]

Msg NATS.Client.Connection.Request ( Msg  message)

Sends a request payload and returns the response Msg.

Request(Msg) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server. The reply subject will be overridden.
Returns
A Msg with the response from the NATS server.
Exceptions
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [2/10]

Msg NATS.Client.Connection.Request ( Msg  message,
int  timeout 
)

Sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

Request(Msg) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server. The reply subject will be overridden.
timeoutThe number of milliseconds to wait.
Returns
A Msg with the response from the NATS server.
Exceptions
ArgumentOutOfRangeExceptiontimeout is less than or equal to zero (0).
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [3/10]

Msg NATS.Client.Connection.Request ( string  subject,
byte[]  data 
)

Sends a request payload and returns the response Msg.

Request(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
Returns
A Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [4/10]

Msg NATS.Client.Connection.Request ( string  subject,
byte[]  data,
int  offset,
int  count 
)

Sends a sequence of bytes as the request payload and returns the response Msg.

NATS supports two flavors of request-reply messaging: point-to-point or one-to-many. Point-to-point involves the fastest or first to respond. In a one-to-many exchange, you set a limit on the number of responses the requestor may receive and instead must use a subscription (ISubscription.AutoUnsubscribe(int)). In a request-response exchange, publish request operation publishes a message with a reply subject expecting a response on that reply subject.

Request(string, byte[], int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
Returns
A Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [5/10]

Msg NATS.Client.Connection.Request ( string  subject,
byte[]  data,
int  offset,
int  count,
int  timeout 
)

Sends a sequence of bytes as the request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

Request(string, byte[], int, int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
timeoutThe number of milliseconds to wait.
Returns
A Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Request() [6/10]

Msg NATS.Client.Connection.Request ( string  subject,
byte[]  data,
int  timeout 
)

Sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

Request(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
Returns
A Msg with the response from the NATS server.
Exceptions
ArgumentOutOfRangeExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [7/10]

Msg NATS.Client.Connection.Request ( string  subject,
MsgHeader  headers,
byte[]  data 
)

Sends a request payload and returns the response Msg.

Request(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
Returns
A Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Request() [8/10]

Msg NATS.Client.Connection.Request ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count 
)

Sends a sequence of bytes as the request payload and returns the response Msg.

NATS supports two flavors of request-reply messaging: point-to-point or one-to-many. Point-to-point involves the fastest or first to respond. In a one-to-many exchange, you set a limit on the number of responses the requestor may receive and instead must use a subscription (ISubscription.AutoUnsubscribe(int)). In a request-response exchange, publish request operation publishes a message with a reply subject expecting a response on that reply subject.

Request(string, byte[], int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
Returns
A Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ Request() [9/10]

Msg NATS.Client.Connection.Request ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count,
int  timeout 
)

Sends a sequence of bytes as the request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

Request(string, byte[], int, int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
timeoutThe number of milliseconds to wait.
Returns
A Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ Request() [10/10]

Msg NATS.Client.Connection.Request ( string  subject,
MsgHeader  headers,
byte[]  data,
int  timeout 
)

Sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

Request(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
Returns
A Msg with the response from the NATS server.
Exceptions
ArgumentOutOfRangeExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [1/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( Msg  message)

Asynchronously sends a request message and returns the response Msg.

RequestAsync(Msg) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [2/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( Msg  message,
CancellationToken  token 
)

Asynchronously sends a request message and returns the response Msg, while monitoring for cancellation requests.

RequestAsync(Msg, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [3/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( Msg  message,
int  timeout 
)

Asynchronously sends a request message and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

RequestAsync(Msg, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [4/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( Msg  message,
int  timeout,
CancellationToken  token 
)

Asynchronously sends a request message and returns the response Msg, or throws NATSTimeoutException if the timeout expires, while monitoring for cancellation requests.

RequestAsync(Msg, int, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
messageA NATS Msg that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
ArgumentNullExceptionmessage is null.
NATSBadSubscriptionExceptionThe message subject is null or entirely whitespace.
NATSMaxPayloadExceptionMessage data exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [5/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data 
)

Asynchronously sends a request payload and returns the response Msg.

RequestAsync(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [6/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
CancellationToken  token 
)

Asynchronously sends a request payload and returns the response Msg, while monitoring for cancellation requests.

RequestAsync(string, byte[], CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [7/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
int  offset,
int  count 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg.

RequestAsync(string, byte[], int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [8/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
int  offset,
int  count,
CancellationToken  token 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg, while monitoring for cancellation requests.

RequestAsync(string, byte[], int, int, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [9/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
int  offset,
int  count,
int  timeout 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

RequestAsync(string, byte[], int, int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
timeoutThe number of milliseconds to wait.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [10/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
int  timeout 
)

Asynchronously sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

RequestAsync(string, byte[], int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [11/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
byte[]  data,
int  timeout,
CancellationToken  token 
)

Asynchronously sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires, while monitoring for cancellation requests.

RequestAsync(string, byte[], int, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [12/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data 
)

Asynchronously sends a request payload and returns the response Msg.

RequestAsync(string, byte[]) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [13/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
CancellationToken  token 
)

Asynchronously sends a request payload and returns the response Msg, while monitoring for cancellation requests.

RequestAsync(string, byte[], CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [14/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg.

RequestAsync(string, byte[], int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [15/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count,
CancellationToken  token 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg, while monitoring for cancellation requests.

RequestAsync(string, byte[], int, int, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [16/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
int  offset,
int  count,
int  timeout 
)

Asynchronously sends a sequence of bytes as the request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

RequestAsync(string, byte[], int, int, int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
offsetThe zero-based byte offset in data at which to begin publishing bytes to the subject.
countThe number of bytes to be published to the subject.
timeoutThe number of milliseconds to wait.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
See also
IConnection.Request(string, byte[])
Exceptions
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.

Implements NATS.Client.IConnection.

◆ RequestAsync() [17/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
int  timeout 
)

Asynchronously sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires.

RequestAsync(string, byte[], int) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ RequestAsync() [18/18]

Task< Msg > NATS.Client.Connection.RequestAsync ( string  subject,
MsgHeader  headers,
byte[]  data,
int  timeout,
CancellationToken  token 
)

Asynchronously sends a request payload and returns the response Msg, or throws NATSTimeoutException if the timeout expires, while monitoring for cancellation requests.

RequestAsync(string, byte[], int, CancellationToken) will create an unique inbox for this request, sharing a single subscription for all replies to this Connection instance. However, if Options.UseOldRequestStyle is set, each request will have its own underlying subscription. The old behavior is not recommended as it may cause unnecessary overhead on connected NATS servers.

Parameters
subjectThe subject to publish data to over the current connection.
headersOptional headers to publish with the message.
dataAn array of type Byte that contains the request data to publish to the connected NATS server.
timeoutThe number of milliseconds to wait.
tokenThe token to monitor for cancellation requests.
Returns
A task that represents the asynchronous read operation. The value of the Task<TResult>.Result parameter contains a Msg with the response from the NATS server.
Exceptions
ArgumentExceptiontimeout is less than or equal to zero (0).
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSMaxPayloadExceptiondata exceeds the maximum payload size supported by the NATS server.
NATSConnectionClosedExceptionThe Connection is closed.
NATSTimeoutExceptionA timeout occurred while sending the request or receiving the response.
NATSNoRespondersExceptionNo responders are available for this request.
NATSExceptionThere was an unexpected exception performing an internal NATS call while executing the request. See Exception.InnerException for more details.
OperationCanceledExceptionThe asynchronous operation was cancelled or timed out before it could be completed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ ResetStats()

void NATS.Client.Connection.ResetStats ( )

Resets the associated statistics for the Connection.

See also
Stats

Implements NATS.Client.IConnection.

◆ RTT()

TimeSpan NATS.Client.Connection.RTT ( )

Returns
A timespan representing the elapsed time.

Returns
Exceptions
NATSConnectionClosedExceptionIf the connection is closed.
NATSExceptionMiscellaneous other exceptions

Implements NATS.Client.IConnection.

◆ SubscribeAsync() [1/4]

IAsyncSubscription NATS.Client.Connection.SubscribeAsync ( string  subject)

Expresses interest in the given subject to the NATS Server.

The IAsyncSubscription returned will not start receiving messages until IAsyncSubscription.Start is called.

Parameters
subjectThe subject on which to listen for messages. The subject can have wildcards (partial: *, full: >).
Returns
An IAsyncSubscription to use to read any messages received from the NATS Server on the given subject .
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ SubscribeAsync() [2/4]

IAsyncSubscription NATS.Client.Connection.SubscribeAsync ( string  subject,
EventHandler< MsgHandlerEventArgs handler 
)

Expresses interest in the given subject to the NATS Server, and begins delivering messages to the given event handler.

The IAsyncSubscription returned will start delivering messages to the event handler as soon as they are received. The caller does not have to invoke IAsyncSubscription.Start.

Parameters
subjectThe subject on which to listen for messages. The subject can have wildcards (partial: *, full: >).
handlerThe EventHandler<TEventArgs> invoked when messages are received on the returned IAsyncSubscription.
Returns
An IAsyncSubscription to use to read any messages received from the NATS Server on the given subject .
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ SubscribeAsync() [3/4]

IAsyncSubscription NATS.Client.Connection.SubscribeAsync ( string  subject,
string  queue 
)

Creates an asynchronous queue subscriber on the given subject .

The IAsyncSubscription returned will not start receiving messages until IAsyncSubscription.Start is called.

Parameters
subjectThe subject on which to listen for messages. The subject can have wildcards (partial: *, full: >).
queueThe name of the queue group in which to participate.
Returns
An IAsyncSubscription to use to read any messages received from the NATS Server on the given subject .
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ SubscribeAsync() [4/4]

IAsyncSubscription NATS.Client.Connection.SubscribeAsync ( string  subject,
string  queue,
EventHandler< MsgHandlerEventArgs handler 
)

Creates an asynchronous queue subscriber on the given subject , and begins delivering messages to the given event handler.

The IAsyncSubscription returned will start delivering messages to the event handler as soon as they are received. The caller does not have to invoke IAsyncSubscription.Start.

Parameters
subjectThe subject on which to listen for messages. The subject can have wildcards (partial: *, full: >).
queueThe name of the queue group in which to participate.
handlerThe EventHandler<TEventArgs> invoked when messages are received on the returned IAsyncSubscription.
Returns
An IAsyncSubscription to use to read any messages received from the NATS Server on the given subject .
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ SubscribeSync() [1/2]

ISyncSubscription NATS.Client.Connection.SubscribeSync ( string  subject)

Expresses interest in the given subject to the NATS Server.

Parameters
subjectThe subject on which to listen for messages. The subject can have wildcards (partial: *, full: >).
Returns
An ISyncSubscription to use to read any messages received from the NATS Server on the given subject .
Exceptions
NATSBadSubscriptionExceptionsubject is null or entirely whitespace.
NATSConnectionClosedExceptionThe Connection is closed.
IOExceptionThere was a failure while writing to the network.

Implements NATS.Client.IConnection.

◆ SubscribeSync() [2/2]

ISyncSubscription NATS.Client.Connection.SubscribeSync ( string  subject,
string  queue 
)

Creates a synchronous queue subscriber on the given subject .

All subscribers with the same queue name will form the queue group and only one member of the group will be selected to receive any given message synchronously.

Parameters
subjectThe subject on which to listen for messages.
queueThe name of the queue group in which to participate.
Returns
An ISyncSubscription to use to read any messages received from the NATS Server on the given subject , as part of the given queue group.

Implements NATS.Client.IConnection.

◆ ToString()

override string NATS.Client.Connection.ToString ( )

Returns a string representation of the value of this Connection instance.

Returns
A string that represents the current instance.

Property Documentation

◆ ClientID

int NATS.Client.Connection.ClientID
get

Gets the ID of client as known by the NATS server, otherwise null.

May not be supported in all versions of the server. If the client is connected to an older server or is in the process of connecting, 0 will be returned.

Implements NATS.Client.IConnection.

◆ ClientIP

IPAddress NATS.Client.Connection.ClientIP
get

Gets the IP of client as known by the NATS server, otherwise null.

Supported in the NATS server version 2.1.6 and above. If the client is connected to an older server or is in the process of connecting, null will be returned.

Implements NATS.Client.IConnection.

◆ DiscoveredServers

string [] NATS.Client.Connection.DiscoveredServers
get

Gets an array of server URLs that were discovered after this instance connected.

If authentication is enabled, Options.User or Options.Token must be used when connecting with these URLs.

Implements NATS.Client.IConnection.

◆ MaxPayload

◆ Servers

string [] NATS.Client.Connection.Servers
get

Gets an array of known server URLs for this instance.

Servers also includes any additional servers discovered after a connection has been established. If authentication is enabled, Options.User or Options.Token must be used when connecting with these URLs.

Implements NATS.Client.IConnection.

◆ State

ConnState NATS.Client.Connection.State
get

Gets the current state of the Connection.

See also
ConnState

Implements NATS.Client.IConnection.

◆ Stats

IStatistics NATS.Client.Connection.Stats
get

Gets the statistics tracked for the Connection.

See also
ResetStats

Implements NATS.Client.IConnection.


The documentation for this class was generated from the following file: