RTI Connext Traditional C++ API Version 7.1.0
Request-Reply Examples

Examples on how to use the request-reply API .

Examples on how to use the request-reply API .

Request-Reply code examples.

Request-Reply Examples

Requesters and Repliers provide a way to use the Request-Reply communication pattern on top of the DDS entities. An application uses a Requester to send requests to a Replier; another application using a Replier receives a request and can send one or more replies for that request. The Requester that sent the request (and only that one) will receive the reply (or replies).

DDS Types

RTI Connext uses DDS data types for sending and receiving requests and replies. Valid types are those generated by the rtiddsgen code generator, the DDS built-in types, and DynamicData. Refer to the Core Libraries User's Manual and the following links for more information:

Set up

Requester: sending requests and receiving replies

Replier: receiving requests and sending replies

Error handling

Note
To use Request-Reply you need to build and link your application with the additional rticonnextmsgcpp library and include ndds/ndds_requestreply_cpp.h.

Requester Creation

Creating a Requester with optional parameters

See also
Requester Creation
Configuring Request-Reply QoS profiles

Basic Requester example

Taking loaned samples

See also
Basic Requester example
Basic Replier example
Taking samples by copy

Taking samples by copy

See also
Basic Replier example
Taking loaned samples

Correlating requests and replies

See also
Basic Requester example
Basic Replier example

Basic Requester example using SampleRef

This example is similar to Basic Requester example except it uses a SampleRef instance instead of a Sample instance.

Creating a Replier

Basic Replier example

See also
Basic Requester example

SimpleReplier example

Error handling example

Configuring Request-Reply QoS profiles

If you do not specify your own QoS parameters (in connext::RequesterParams and connext::ReplierParams), a connext::Requester and connext::Replier are created using a default configuration. That configuration is equivalent to the one in the following QoS profile called "default":

<?xml version="1.0"?>
<!--
Description
XML QoS Profile for HelloWorld
(c) Copyright, Real-Time Innovations, 2012. All rights reserved.
RTI grants Licensee a license to use, modify, compile, and create derivative
works of the software solely for use with RTI Connext DDS. Licensee may
redistribute copies of the software provided that all such copies are
subject to this license. The software is provided "as is", with no warranty
of any type, including any warranty for fitness for any purpose. RTI is
under no obligation to maintain or support the software. RTI shall not be
liable for any incidental or consequential damages arising out of the use
or inability to use the software.
The QoS configuration of the DDS entities in the generated example is loaded
from this file.
This file is used only when it is in the current working directory or when the
environment variable NDDS_QOS_PROFILES is defined and points to this file.
The profile in this file inherits from the builtin QoS profile
BuiltinQosLib::Generic.StrictReliable. That profile, along with all of the
other built-in QoS profiles can be found in the
BuiltinProfiles.documentationONLY.xml file located in the
$NDDSHOME/resource/xml/ directory.
You may use any of these QoS configurations in your application simply by
referring to them by the name shown in the
BuiltinProfiles.documentationONLY.xml file.
Also, following the QoS Profile composition pattern you can use QoS Snippets
to easily create your final QoS Profile. For further information visit:
https://community.rti.com/best-practices/qos-profile-inheritance-and-composition-guidance
There is a QoS Snippet library that contains a collection of
QoS Snippets that set some specific features or configurations. You can find
them in the BuiltinProfiles.documentationONLY.xml file as well.
You should not edit the file BuiltinProfiles.documentationONLY.xml directly.
However, if you wish to modify any of the values in a built-in profile, the
recommendation is to create a profile of your own and inherit from the built-in
profile you wish to modify. The NDDS_QOS_PROFILES.example.xml file (contained in
the same directory as the BuiltinProfiles.documentationONLY.xml file) shows how
to inherit from the built-in profiles.
For more information about XML QoS Profiles see the "Configuring QoS with
XML" chapter in the RTI Connext DDS Core Libraries User's Manual.
-->
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:////rti/jenkins/workspace/connextdds_htmldocs_support_connextdds-doc_7.1.0/build/nddsgen.2.0/resource/schema/rti_dds_qos_profiles.xsd">
<!-- QoS Library containing the QoS profile used in the generated example.
A QoS library is a named set of QoS profiles.
-->
<qos_library name="HelloWorld_Library">
<!-- QoS profile used to configure reliable communication between the DataWriter
and DataReader created in the example code.
A QoS profile groups a set of related QoS.
-->
<qos_profile name="HelloWorld_Profile" base_name="BuiltinQosLib::Generic.StrictReliable" is_default_qos="true">
<!-- QoS used to configure the data writer created in the example code -->
<datawriter_qos>
<publication_name>
<name>HelloWorldDataWriter</name>
</publication_name>
</datawriter_qos>
<!-- QoS used to configure the data reader created in the example code -->
<datareader_qos>
<subscription_name>
<name>HelloWorldDataReader</name>
</subscription_name>
</datareader_qos>
<domain_participant_qos>
<!--
The participant name, if it is set, will be displayed in the
RTI tools, making it easier for you to tell one
application from another when you're debugging.
-->
<participant_name>
<name>HelloWorldParticipant</name>
<role_name>HelloWorldParticipantRole</role_name>
</participant_name>
</domain_participant_qos>
</qos_profile>
</qos_library>
</dds>

You can use the profile called "RequesterExampleProfile", which modifies some parameters from the default. The example Creating a Requester with optional parameters shows how to create a connext::Requester using this profile.

See also
Creating a Requester with optional parameters
Configuring QoS Profiles with XML