Table of Contents

Method ConsumeAsync

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

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

Starts consuming messages from the ordered push consumer.

public IAsyncEnumerable<INatsJSMsg<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. Only NotificationHandler is applicable: it receives NatsJSTimeoutNotification when no messages or heartbeats arrive within twice the idle heartbeat interval (default 5 seconds, i.e. 10 seconds of silence), at which point the underlying consumer is recreated automatically. The remaining options (e.g. MaxMsgs, Expires, IdleHeartbeat, ThresholdMsgs, ThresholdBytes) control pull-consumer behavior and are not applicable to ordered push consumers.

cancellationToken CancellationToken

A CancellationToken used to cancel consume operations.

Returns

IAsyncEnumerable<INatsJSMsg<T>>

An asynchronous enumerable of messages.

Type Parameters

T

Message type to deserialize.

Exceptions

NatsJSProtocolException

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