Table of Contents

Method CreatePushConsumerAsync

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

CreatePushConsumerAsync(string, NatsJSPushConsumerOpts?, CancellationToken)

Creates a new push consumer that delivers messages to the subject given in DeliverSubject.

public ValueTask<INatsJSPushConsumer> CreatePushConsumerAsync(string stream, NatsJSPushConsumerOpts? opts = null, CancellationToken cancellationToken = default)

Parameters

stream string

Name of the stream to create the consumer under.

opts NatsJSPushConsumerOpts

Push consumer options.

cancellationToken CancellationToken

A CancellationToken used to cancel the API call.

Returns

ValueTask<INatsJSPushConsumer>

The NATS JetStream push consumer object which can be used retrieving data from the stream with ConsumeAsync<T>(INatsDeserialize<T>?, NatsJSConsumeOpts?, CancellationToken).

Remarks

Ephemeral push consumers (no Name or DurableName) are automatically deleted by the server roughly 5 seconds after the delivery subject loses interest. This means the consumer is also removed if ConsumeAsync<T>(INatsDeserialize<T>?, NatsJSConsumeOpts?, CancellationToken) is not started within that window after creation, or if the connection stays disconnected longer than the threshold. Use a durable consumer, a DeliverGroup or a longer InactiveThreshold for consumption that may be delayed.

Exceptions

NatsJSException

There was an issue retrieving the response, or DeliverSubject is not set.

NatsJSApiException

Server responded with an error.

ArgumentException

The stream name is invalid.

ArgumentNullException

The stream name is null.