Method SubscribeCoreAsync
SubscribeCoreAsync<T>(string, string?, INatsDeserialize<T>?, NatsSubOpts?, CancellationToken)
Initiates a subscription to a subject, optionally joining a distributed queue group and returns a INatsSub<T> object which provides more control over the subscription.
public ValueTask<INatsSub<T>> SubscribeCoreAsync<T>(string subject, string? queueGroup = null, INatsDeserialize<T>? serializer = null, NatsSubOpts? opts = null, CancellationToken cancellationToken = default)
Parameters
subject
stringThe subject name to subscribe to.
queueGroup
stringIf specified, the subscriber will join this queue group.
serializer
INatsDeserialize<T>Serializer to use for the message type.
opts
NatsSubOptsA NatsSubOpts for subscription options.
cancellationToken
CancellationTokenA CancellationToken used to cancel the command.
Returns
Type Parameters
T
Specifies the type of data that may be received from the NATS Server.
Remarks
Subscribers with the same queue group name, become a queue group, and only one randomly chosen subscriber of the queue group will consume a message each time a message is received by the queue group.
This method returns a INatsSub<T> object which provides slightly lower level control over the subscription. You can use this object to create your own core messaging patterns or to create your own higher level abstractions.