RTI Connext C# API Version 7.2.0
Rti.RequestReply.Requester< TRequest, TReply > Class Template Reference

Allows sending requests and receiving replies. More...

Inherits IDisposable.

Public Member Functions

SampleIdentity SendRequest (TRequest request)
 Sends a request. More...
 
void SendRequest (TRequest request, WriteParams writeParams)
 Sends a request. More...
 
LoanedSamples< TReply > ReceiveReplies (int minCount, Duration maxWait)
 Receives a number of replies. More...
 
LoanedSamples< TReply > TakeReplies ()
 Takes all replies. More...
 
LoanedSamples< TReply > TakeReplies (SampleIdentity relatedRequestId)
 Takes all of the replies for a specific request identified by a SampleIdentity. More...
 
LoanedSamples< TReply > ReadReplies ()
 Reads all replies. More...
 
LoanedSamples< TReply > ReadReplies (SampleIdentity relatedRequestId)
 Reads all of the replies for a specific request, identified by a SampleIdentity. More...
 
bool WaitForReplies (int minCount, Duration maxWait)
 Wait for a number of replies for a duration of time. More...
 
bool WaitForReplies (int minCount, SampleIdentity relatedRequestId, Duration maxWait)
 Wait for a number of replies identified by a SampleIdentity. for a duration of time. More...
 
async Task< int > WaitForRepliesAsync (int minCount=1, CancellationToken cancellationToken=default)
 Wait for a number of replies asynchronously until a minimum number of replies reach the Requester, or a cancellation is requested using a CancellationToken, More...
 
async Task< int > WaitForRepliesAsync (int minCount, SampleIdentity relatedRequestId, CancellationToken cancellationToken=default)
 Wait for a number of replies identified by a SampleIdentity asynchronously until a minimum number of replies reach the Requester, or a cancellation is requested using a CancellationToken, More...
 
uint GetMatchedReplierCount ()
 Returns the number of Replier's that are currently matched with this Requester. More...
 
void Dispose ()
 Releases the native resources used by this object. More...
 

Properties

DataWriter< TRequest > RequestWriter [get]
 The underlying DataWriter<TRequest> used to send requests. More...
 
DataReader< TReply > ReplyReader [get]
 The underlying DataReader<TReply> used to read replies. More...
 

Detailed Description

Allows sending requests and receiving replies.

Template Parameters
TRequestThe type of the requests to be sent.
TReplyThe type of the replies to be received.

A Requester is an entity with two associated topics: a request topic and a reply topic. It can send requests by publishing samples of the request topic and receive replies to those requests by subscribing to the reply topic.

Valid types for these topics are: those generated by the rtiddsgen code generator, the DDS built-in types and Rti.Types.Dynamic.DynamicData.

A Replier and a Requester communicate when they use the same topics for requests and replies (see RequesterBuilder<TRequest, TReply>.WithServiceName) on the same domain ID. A Requester can send requests and receive one or multiple replies. It does that using the following operations:

  • Sending requests (i.e. publishing request samples on the request topic)
  • Waiting for replies to be received by the middleware (for any request or for a specific request)
  • Getting those replies from the middleware. There are two ways to do this: take (the data samples are removed from the middleware) or read (the data samples remain in the middleware and can be read or taken again).
  • A convenience operation, receive (which is a combination of wait and take).

In all cases, the middleware guarantees that a requester only receives reply samples that are associated with those requests that it sends.

For multi-reply scenarios, in which a Requester receives multiple replies from a Replier for a given request, the Requester can check if a reply is the last reply of a sequence of replies. To do so, see if the bit SampleFlags.IntermediateReplySequence is set in Rti.Dds.Subscription.SampleInfo.Flag after receiving each reply. This indicates it is NOT the last reply.

A Requester has an associated Rti.Dds.Domain.DomainParticipant, which can be shared with other requesters or RTI Connext routines. All the other RTI Connext entities required for the request-reply interaction, including a DataWriter<TRequest> for writing requests and a DataReader<TReply> for reading replies, are automatically created when the requester is constructed.

Quality of Service for the underlying DataWriter and DataReader can be configured (see RequesterBuilder<TRequest, TReply>.WithDataWriterQos and RequesterBuilder<TRequest, TReply>.WithDataReaderQos). By default, they are created with Rti.Dds.Core.Policy.ReliabilityKind.Reliable. The exact default QoS configuration is described in the Modern C++ API: Configuring Request-Reply QoS profiles.

Use participant.BuildRequester<TRequest, TReply>() (an extension method defined in DomainParticipantRequestReplyExtensions) to configure and build a Requester.

For example, to create a basic Requester:

var requester = participant.BuildRequester<FooRequest, FooReply>()
.WithServiceName("FooService")
.Create();
See also
Request-Reply Examples

Member Function Documentation

◆ SendRequest() [1/2]

SampleIdentity Rti.RequestReply.Requester< TRequest, TReply >.SendRequest ( TRequest  request)
inline

Sends a request.

Parameters
requestThe request to be sent.
Returns
The identity of the request, which can be used to correlate it with a future reply.

◆ SendRequest() [2/2]

void Rti.RequestReply.Requester< TRequest, TReply >.SendRequest ( TRequest  request,
WriteParams  writeParams 
)

Sends a request.

Parameters
requestThe request to be sent.
writeParamsThe parameters to write the request (see DataWriter<TRequest>.Write(TRequest, WriteParams))

This function allows setting the request identity in writeParams.Identity , among other advanced parameters. If the identity is not set, Connext automatically assigns it, and to obtain it writeParams.ReplaceAuto needs to be set to true. Then, after this function ends, writeParams.Identity will contain the request identity. If no additional parameters need to be set, use the simpler SendRequest(TRequest), which directly returns the automatically assigned identity.

◆ ReceiveReplies()

LoanedSamples< TReply > Rti.RequestReply.Requester< TRequest, TReply >.ReceiveReplies ( int  minCount,
Duration  maxWait 
)

Receives a number of replies.

Parameters
minCountThe minimum number of replies to wait for.
maxWaitMaximum time to wait for the replies.
Returns
A LoanedSamples<TReply> object containing the replies.

◆ TakeReplies() [1/2]

LoanedSamples< TReply > Rti.RequestReply.Requester< TRequest, TReply >.TakeReplies ( )

Takes all replies.

Returns
A LoanedSamples<TReply> object containing the replies.

◆ TakeReplies() [2/2]

LoanedSamples< TReply > Rti.RequestReply.Requester< TRequest, TReply >.TakeReplies ( SampleIdentity  relatedRequestId)
inline

Takes all of the replies for a specific request identified by a SampleIdentity.

Parameters
relatedRequestIdIdentifies a request previously sent by SendRequest(TRequest)
Returns
A LoanedSamples<TReply> object containing the replies.

◆ ReadReplies() [1/2]

LoanedSamples< TReply > Rti.RequestReply.Requester< TRequest, TReply >.ReadReplies ( )

Reads all replies.

Returns
A LoanedSamples<TReply> object containing the replies.

◆ ReadReplies() [2/2]

LoanedSamples< TReply > Rti.RequestReply.Requester< TRequest, TReply >.ReadReplies ( SampleIdentity  relatedRequestId)
inline

Reads all of the replies for a specific request, identified by a SampleIdentity.

Parameters
relatedRequestIdIdentifies a request previously sent by SendRequest(TRequest).
Returns
A LoanedSamples<TReply> object containing the replies.

◆ WaitForReplies() [1/2]

bool Rti.RequestReply.Requester< TRequest, TReply >.WaitForReplies ( int  minCount,
Duration  maxWait 
)

Wait for a number of replies for a duration of time.

Parameters
minCountThe minimum number of replies to wait for.
maxWaitMaximum time to wait for the replies.
Returns
A bool indicating whether or not the number of specified replies have reached the Requester.

◆ WaitForReplies() [2/2]

bool Rti.RequestReply.Requester< TRequest, TReply >.WaitForReplies ( int  minCount,
SampleIdentity  relatedRequestId,
Duration  maxWait 
)
inline

Wait for a number of replies identified by a SampleIdentity. for a duration of time.

Parameters
minCountThe minimum number of replies to wait for.
relatedRequestIdIdentifies a request previously sent by SendRequest(TRequest).
maxWaitMaximum time to wait for the replies.
Returns
A bool indicating whether or not the number of specified replies have reached the Requester.

◆ WaitForRepliesAsync() [1/2]

async Task< int > Rti.RequestReply.Requester< TRequest, TReply >.WaitForRepliesAsync ( int  minCount = 1,
CancellationToken  cancellationToken = default 
)

Wait for a number of replies asynchronously until a minimum number of replies reach the Requester, or a cancellation is requested using a CancellationToken,

Parameters
minCountThe minimum number of replies to wait for.
cancellationTokenA cancellation token for the wait.
Returns
A Task containing the number of replies that have reached the Requester while waiting.

◆ WaitForRepliesAsync() [2/2]

async Task< int > Rti.RequestReply.Requester< TRequest, TReply >.WaitForRepliesAsync ( int  minCount,
SampleIdentity  relatedRequestId,
CancellationToken  cancellationToken = default 
)
inline

Wait for a number of replies identified by a SampleIdentity asynchronously until a minimum number of replies reach the Requester, or a cancellation is requested using a CancellationToken,

Parameters
minCountThe minimum number of replies to wait for.
relatedRequestIdIdentifies a request previously sent by SendRequest(TRequest).
cancellationTokenA cancellation token for the wait.
Returns
A Task containing the number of replies that have reached the Requester while waiting.

◆ GetMatchedReplierCount()

uint Rti.RequestReply.Requester< TRequest, TReply >.GetMatchedReplierCount ( )

Returns the number of Replier's that are currently matched with this Requester.

Returns
The number of matching Replier's.

◆ Dispose()

void Rti.RequestReply.Requester< TRequest, TReply >.Dispose ( )
inline

Releases the native resources used by this object.

Property Documentation

◆ RequestWriter

DataWriter<TRequest> Rti.RequestReply.Requester< TRequest, TReply >.RequestWriter
get

The underlying DataWriter<TRequest> used to send requests.

◆ ReplyReader

DataReader<TReply> Rti.RequestReply.Requester< TRequest, TReply >.ReplyReader
get

The underlying DataReader<TReply> used to read replies.