Table of Contents

Method FetchAsync

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

FetchAsync<T>(NatsJSFetchOpts, INatsDeserialize<T>?, CancellationToken)

Consume a set number of messages from the stream using this consumer.

public IAsyncEnumerable<NatsJSMsg<T>> FetchAsync<T>(NatsJSFetchOpts opts, INatsDeserialize<T>? serializer = null, CancellationToken cancellationToken = default)

Parameters

opts NatsJSFetchOpts

Fetch options. (default: MaxMsgs 1,000 and timeout in 30 seconds)

serializer INatsDeserialize<T>

Serializer to use for the message type.

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.

NatsJSException

There is an error sending the message or this consumer object isn't valid anymore because it was deleted earlier.