RTI Connext C# API  7.1.0
Replier< TRequest, TReply > Class Template Reference

Allows receiving requests and sending replies. More...

Inherits IDisposable.

Public Member Functions

void SendReply (TReply reply, SampleIdentity relatedRequestId)
 Sends a reply to a specific request identified by a SampleIdentity. More...
 
void SendReply (TReply reply, SampleInfo relatedRequestInfo)
 Sends a reply to a specific request identified by a SampleInfo. More...
 
void SendReply (TReply reply, WriteParams writeParams)
 Sends a reply. More...
 
bool WaitForRequests (int minCount, Duration maxWait)
 Wait for a number of requests for a duration of time. More...
 
async Task< int > WaitForRequestsAsync (int minCount=1, CancellationToken cancellationToken=default)
 Wait for a number of requests asynchronously until a minimum number of requests reach the Replier, or a cancellation is requested using a CancellationToken. More...
 
LoanedSamples< TRequest > ReceiveRequests (int minCount, Duration maxWait)
 Receives a number of requests. More...
 
LoanedSamples< TRequest > TakeRequests ()
 Takes all requests. More...
 
LoanedSamples< TRequest > ReadRequests ()
 Reads all requests. More...
 
void ResetEvents ()
 Stop notifying of RequestsAvailable events and remove all its event handlers. More...
 
uint GetMatchedRequesterCount ()
 Gets the number of Requester's that are currently matched with this Replier. More...
 
void Dispose ()
 Releases the native resources used by this object. More...
 

Properties

DataReader< TRequest > RequestReader [get]
 The underlying DataReader<TRequest> used to read requests. More...
 
DataWriter< TReply > ReplyWriter [get]
 The underlying DataWriter<TReply> used to send replies. More...
 
Action< Replier< TRequest, TReply > > RequestsAvailable
 Event triggered new requests are available on the Replier. More...
 

Detailed Description

Allows receiving requests and sending replies.

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

A Replier is an entity with two associated topics: a request topic and a reply topic. It can receive requests by subscribing to the request topic and can send replies to those requests by publishing 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 has four main types of operations:

  • Waiting for requests to be received from the middleware.
  • Getting those requests.
  • Receiving requests (a convenience operation that is a combination of waiting and getting in a single operation).
  • Sending a reply for a previously received request (i.e., publishing a reply sample on the reply topic with special meta-data so that the original Requester can identify it).

For multi-reply scenarios in which a Replier generates more than one reply for a request, the Replier should mark all the intermediate replies (all but the last) using the SampleFlags.IntermediateReplySequence flag in Rti.Dds.Subscription.SampleInfo.Flag.

A Replier 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<TReply> for writing replies and a DataReader<TRequest> for reading requests, are automatically created when the replier is constructed.

Quality of Service for the underlying DataWriter and DataReader can be configured (see ReplierBuilder<TRequest, TReply>.WithDataWriterQos and ReplierBuilder<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.

There are several ways to use a Replier:

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

For example, to create a basic Replier:

var replier = participant.BuildReplier<FooRequest, FooReply>()
.WithServiceName("FooService")
.Create();

See also Request-Reply Examples.

Member Function Documentation

◆ Dispose()

void Dispose ( )

Releases the native resources used by this object.

◆ GetMatchedRequesterCount()

uint GetMatchedRequesterCount ( )

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

Returns
The number of matching Requester's.

◆ ReadRequests()

LoanedSamples<TRequest> ReadRequests ( )

Reads all requests.

Returns
A LoanedSamples<TRequest> object containing the requests.

◆ ReceiveRequests()

LoanedSamples<TRequest> ReceiveRequests ( int  minCount,
Duration  maxWait 
)

Receives a number of requests.

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

◆ ResetEvents()

void ResetEvents ( )

Stop notifying of RequestsAvailable events and remove all its event handlers.

◆ SendReply() [1/3]

void SendReply ( TReply  reply,
SampleIdentity  relatedRequestId 
)

Sends a reply to a specific request identified by a SampleIdentity.

Parameters
replyThe reply to be sent.
relatedRequestIdIdentifies a request previously sent by Requester<TRequest, TReply>.SendRequest(TRequest).

◆ SendReply() [2/3]

void SendReply ( TReply  reply,
SampleInfo  relatedRequestInfo 
)

Sends a reply to a specific request identified by a SampleInfo.

Parameters
replyThe reply to be sent.
relatedRequestInfoIdentifies a request previously sent by Requester<TRequest, TReply>.SendRequest(TRequest).

◆ SendReply() [3/3]

void SendReply ( TReply  reply,
WriteParams  writeParams 
)

Sends a reply.

Parameters
replyThe reply to be sent.
writeParamsThe parameters to write the reply.

Other parameters to customize are discussed in DataWriter<T>.Write(T, WriteParams). In particular, Rti.Dds.Publication.WriteParams.Flag can be set to SampleFlags.IntermediateReplySequence to inform the Requester application that this reply will be followed by additional replies to the same request. The Requester can access the flag in Rti.Dds.Subscription.SampleInfo.Flag when it receives the reply.

◆ TakeRequests()

LoanedSamples<TRequest> TakeRequests ( )

Takes all requests.

Returns
A LoanedSamples<TRequest> object containing the requests.

◆ WaitForRequests()

bool WaitForRequests ( int  minCount,
Duration  maxWait 
)

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

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

◆ WaitForRequestsAsync()

async Task<int> WaitForRequestsAsync ( int  minCount = 1,
CancellationToken  cancellationToken = default 
)

Wait for a number of requests asynchronously until a minimum number of requests reach the Replier, or a cancellation is requested using a CancellationToken.

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

Property Documentation

◆ ReplyWriter

DataWriter<TReply> ReplyWriter
get

The underlying DataWriter<TReply> used to send replies.

◆ RequestReader

DataReader<TRequest> RequestReader
get

The underlying DataReader<TRequest> used to read requests.

◆ RequestsAvailable

Action<Replier<TRequest, TReply> > RequestsAvailable
addremove

Event triggered new requests are available on the Replier.