Method ConsumeAsync
ConsumeAsync<T>(INatsDeserialize<T>?, NatsJSConsumeOpts?, CancellationToken)
Starts an enumerator consuming messages from the stream using this consumer.
public 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
NatsJSConsumeOptsConsume options. (default:
MaxMsgs
1,000)cancellationToken
CancellationTokenA 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.