Table of Contents

Method RequestAsync

Namespace
NATS.Client.Core
Assembly
NATS.Client.Core.dll

RequestAsync<TRequest, TReply>(INatsConnection, in NatsMsg<TRequest>, INatsSerialize<TRequest>?, INatsDeserialize<TReply>?, NatsPubOpts?, NatsSubOpts?, CancellationToken)

Request and receive a single reply from a responder.

public static ValueTask<NatsMsg<TReply>> RequestAsync<TRequest, TReply>(this INatsConnection nats, in NatsMsg<TRequest> msg, INatsSerialize<TRequest>? requestSerializer = null, INatsDeserialize<TReply>? replySerializer = null, NatsPubOpts? requestOpts = null, NatsSubOpts? replyOpts = null, CancellationToken cancellationToken = default)

Parameters

nats INatsConnection

NATS connection

msg NatsMsg<TRequest>

Message to be sent as request

requestSerializer INatsSerialize<TRequest>

Serializer to use for the request message type.

replySerializer INatsDeserialize<TReply>

Serializer to use for the reply message type.

requestOpts NatsPubOpts

Request publish options

replyOpts NatsSubOpts

Reply handler subscription options

cancellationToken CancellationToken

Cancel this request

Returns

ValueTask<NatsMsg<TReply>>

Returns the NatsMsg<T> received from the responder as reply.

Type Parameters

TRequest

Request type

TReply

Reply 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