Method FetchAsync
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
optsNatsJSFetchOptsFetch options. (default:
MaxMsgs1,000 and timeout in 30 seconds)serializerINatsDeserialize<T>Serializer to use for the message type.
cancellationTokenCancellationTokenA CancellationToken used to cancel the call.
Returns
- IAsyncEnumerable<NatsJSMsg<T>>
Async enumerable of messages which can be used in a
await foreachloop.
Type Parameters
TMessage 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.