Method PublishAsync
PublishAsync<T>(string, T?, INatsSerialize<T>?, NatsJSPubOpts?, NatsHeaders?, CancellationToken)
Sends data to a stream associated with the subject.
ValueTask<PubAckResponse> PublishAsync<T>(string subject, T? data, INatsSerialize<T>? serializer = null, NatsJSPubOpts? opts = null, NatsHeaders? headers = null, CancellationToken cancellationToken = default)
Parameters
subject
stringSubject to publish the data to.
data
TData to publish.
serializer
INatsSerialize<T>Serializer to use for the message type.
opts
NatsJSPubOptsPublish options.
headers
NatsHeadersOptional message headers.
cancellationToken
CancellationTokenA CancellationToken used to cancel the publishing call or the wait for response.
Returns
- ValueTask<PubAckResponse>
The ACK response to indicate if stream accepted the message as well as additional information like the sequence number of the message stored by the stream.
Type Parameters
T
Type of the data being sent.
Remarks
Note that if the subject isn't backed by a stream or the connected NATS server isn't running with JetStream enabled, this call will hang waiting for an ACK until the request times out.
Exceptions
- NatsJSException
There was a problem receiving the response.