Method RequestAsync
RequestAsync<TRequest, TReply>(string, TRequest?, NatsHeaders?, INatsSerialize<TRequest>?, INatsDeserialize<TReply>?, NatsPubOpts?, NatsSubOpts?, CancellationToken)
Request and receive a single reply from a responder.
public ValueTask<NatsMsg<TReply>> RequestAsync<TRequest, TReply>(string subject, TRequest? data, NatsHeaders? headers = null, INatsSerialize<TRequest>? requestSerializer = null, INatsDeserialize<TReply>? replySerializer = null, NatsPubOpts? requestOpts = null, NatsSubOpts? replyOpts = null, CancellationToken cancellationToken = default)
Parameters
subjectstringSubject of the responder
dataTRequestData to send to responder
headersNatsHeadersOptional message headers
requestSerializerINatsSerialize<TRequest>Serializer to use for the request message type.
replySerializerINatsDeserialize<TReply>Serializer to use for the reply message type.
requestOptsNatsPubOptsRequest publish options
replyOptsNatsSubOptsReply handler subscription options
cancellationTokenCancellationTokenCancel this request
Returns
- ValueTask<NatsMsg<TReply>>
Returns the NatsMsg<T> received from the responder as reply.
Type Parameters
TRequestRequest type
TReplyReply type
Remarks
Response can be (null) or one NatsMsg<T>. Reply option's max messages will be set to 1. If reply option's timeout is not defined, then it will be set to NatsOpts.RequestTimeout.
Exceptions
- OperationCanceledException
Raised when cancellation token is used
RequestAsync<TReply>(string, INatsDeserialize<TReply>?, NatsSubOpts?, CancellationToken)
Send an empty request message and await the reply message asynchronously.
public ValueTask<NatsMsg<TReply>> RequestAsync<TReply>(string subject, INatsDeserialize<TReply>? replySerializer = null, NatsSubOpts? replyOpts = null, CancellationToken cancellationToken = default)
Parameters
subjectstringSubject of the responder
replySerializerINatsDeserialize<TReply>Serializer to use for the reply message type.
replyOptsNatsSubOptsReply handler subscription options
cancellationTokenCancellationTokenCancel this request
Returns
- ValueTask<NatsMsg<TReply>>
Returns the NatsMsg<T> received from the responder as reply.
Type Parameters
TReplyReply type
Remarks
Response can be (null) or one NatsMsg<T>. Reply option's max messages will be set to 1. If reply option's timeout is not defined, then it will be set to NatsOpts.RequestTimeout.
Exceptions
- OperationCanceledException
Raised when cancellation token is used