Download NDDS®
Transcript
5.1 Lesson 6: Publish and Subscribe Reliably
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
for (count=0;;count++) {
printf("Sampling publication, count %d\n", count);
/* modify the data to be sent here */
sprintf(instance->msg, "Hello World! (%d)", count);
if (NddsPublicationSend(publication) !=
NDDS_PUBLICATION_SUCCESS) {
printf("publication %d not sent\n", count);
return 0;
}
NddsUtilitySleep(send_period_sec);
}
return 1;
}
Line 7
We create an NDDSPublicationProperties structure on the stack to tailor the publication behavior for reliability.
Lines 12-13
These lines convert time values from seconds and nanoseconds into RTINtpTime structures. This is our operating system-independent time representation. It is based on the
NTP time format. Time is not represented in a human readable form. Instead it is organized in a way that makes 64 bit arithmetic easy. We have provided a set of functions to
convert to and from RTINtpTime. See Appendix A for details.
Lines 12-21
The steps to create a reliable publication are identical to the best-effort publication, up to
the point of initializing NDDS, registering the NDDS Type, and allocating a publication
instance.
Lines 23-29
Tailor reliable behavior of the publication through publication properties.
When a publication has reliable subscriptions, it is functionally different than a besteffort (unreliable) publication in the following ways:
❏ It checks for acknowledgements from the reliable subscriptions, and resends pre-
❏ In addition to passively checking the acknowledgement messages from the reliable subscriptions, the publication can (optionally) actively poll for the remote
subscription’s receipt status periodically. We set the heartBeatTimeout field to 0.5
second to poll for the subscription status twice a second. This fancy feature is not
necessary for this simple example, but we show it here in case you want to use it
later in your application.
5-3
5. Advanced C
viously published issues if a subscription reports that issue(s) as missing. The
sendQueueSize field of the publication’s property specifies the maximum number
of issues the publication remembers.