Table of Contents

Method ConsumeAsync

Namespace
NATS.Client.JetStream
Assembly
NATS.Client.JetStream.dll

ConsumeAsync<T>(INatsDeserialize<T>?, NatsJSConsumeOpts?, CancellationToken)

Starts an enumerator consuming messages from the stream using this consumer.

IAsyncEnumerable<NatsJSMsg<T>> ConsumeAsync<T>(INatsDeserialize<T>? serializer = null, NatsJSConsumeOpts? opts = null, CancellationToken cancellationToken = default)

Parameters

serializer INatsDeserialize<T>

Serializer to use for the message type.

opts NatsJSConsumeOpts

Consume options. (default: MaxMsgs 1,000)

cancellationToken CancellationToken

A CancellationToken used to cancel the call.

Returns

IAsyncEnumerable<NatsJSMsg<T>>

Async enumerable of messages which can be used in a await foreach loop.

Type Parameters

T

Message type to deserialize.

Exceptions

NatsJSProtocolException

Consumer is deleted, it's push based or request sent to server is invalid.