RTI Connext Modern C++ API Version 7.5.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

Note
To use Request-Reply you need to build and link your application with the additional rticonnextmsgcpp2 library.

Requester Creation

Creating a Requester with optional parameters

See also
Requester Creation
Configuring Request-Reply QoS profiles

Basic Requester example

Correlating requests and replies

See also
Basic Requester example
Basic Replier example

Creating a Replier

Basic Replier example

See also
Basic Requester example

SimpleReplier example

using namespace rti::request;
SimpleReplier<Foo, Bar> replier(
participant,
"TestService",
[](const Foo& request)
{
return Bar(std::string("Simple reply for ") + request.message());
}
);
// After creation the SimpleReplier is already active and the functor will
// be called upon receiving a request.
basic_string< char, rti::core::memory::OsapiAllocator< char > > string
A string convertible to std::string and with similar functionality.
Definition: String.hpp:262
See also
Basic Requester example

Configuring Request-Reply QoS profiles

If you do not specify your own QoS parameters (in RequesterParams and ReplierParams), a rti::request::Requester and rti::request::Replier are created using a default configuration defined in the built-in profile rti::core::builtin_profiles::qos_snippet_lib::pattern_rpc(). You use this built-in profile as the base for your own profiles:

<?xml version="1.0"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/current/rti_dds_profiles.xsd">
<qos_library name="RequestReplyExampleProfiles">
<!-- Use these profiles to customize the Requester or Replier QoS -->
<!-- These profiles inherit from the built-in profile
BuiltinQosLib::Pattern.RPC, which defines the default values for
the DataWriters and DataReaders created by a Requester or Replier
-->
<qos_profile name="RequesterExampleProfile" base_name="BuiltinQosLib::Pattern.RPC">
<!-- Set the QoS for the DataReader created by the Requester -->
<!--
<datareader_qos>
...
</datareader_qos>
-->
<!-- Set the QoS for the DataWriter created by the Requester -->
<!--
<datawriter_qos>
...
</datawriter_qos>
-->
</qos_profile>
<qos_profile name="ReplierExampleProfile" base_name="BuiltinQosLib::Pattern.RPC">
<!-- Set the QoS for the DataReader created by the Replier -->
<!--
<datareader_qos>
...
</datareader_qos>
-->
<!-- Set the QoS for the DataWriter created by the Replier -->
<!--
<datawriter_qos>
...
</datawriter_qos>
-->
</qos_profile>
</qos_library>
</dds>

The example Creating a Requester with optional parameters shows how to create a rti::request::Requester using this profile.

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