You are here: Design Patterns for Rapid Development > Building and Running the News Examples

Building and Running the News Examples

By default, examples are copied into your home directory the first time you run RTI Launcher or any script in <NDDSHOME>/bin. This document refers to the location of the copied examples as <path to examples>.

Wherever you see <path to examples>, replace it with the appropriate path.

Default path to the examples:

Note: You can specify a different location for rti_workspace. You can also specify that you do not want the examples copied to the workspace.

Source code for the news example is in <path to examples>/connext_dds/<language>/news.

The example performs these steps:

1. Parses the command-line arguments.
2. Loads the quality-of-service (QoS) file, USER_QOS_PROFILES.xml, from the current working directory. The middleware does this automatically; you will not see code in the example to do this. For more information on how to use QoS profiles, see the section on "Configuring QoS with XML" in the User's Manual.
3. On the publishing side, sends news articles periodically.
4. On the subscribing side, receives these articles and print them out periodically.

The steps for compiling and running the program are similar to those described in Building and Running “Hello, World”. As with the Hello World example, Java users should use the build and run command scripts in <path to examples>/connext_dds/java/news. Non-Java Windows developers will find the necessary Microsoft Visual Studio solution files in <path to examples>/connext_dds/<language>/news/win32. Appropriate makefiles for building the C, C++, or Ada1Ada support requires a separate add-on product, Ada Language Support. examples on UNIX platforms are in <path to examples>/connext_dds/<language>/news/make.

The news example combines the publisher and subscriber in a single program, which is run from the <path to examples>/connext_dds/<language>/news directory with the argument pub or sub to select the desired behavior. When running with default arguments, you should see output similar to that shown in Building and Running “Hello, World”. To see additional command-line options, run the program without any arguments.

Both the publishing application and the subscribing application operate in a periodic fashion:

The publishing application writes articles from different news outlets at different rates. Each of these articles is numbered consecutively with respect to its news outlet. Every two seconds, the publisher prints a summary of what it wrote in the previous period.

The subscribing application polls the cache of its DataReader every two seconds and prints the data it finds there. (Many real-world applications will choose to process data as soon as it arrives rather than polling for it. For more information about the different ways to read data, select Modules, Programming How-To’s, DataReader Use Cases in the API Reference HTML documentation. In this case, periodic polling makes the behavior easy to illustrate.) Along with each article it prints, it includes the time at which that article was published and whether that article has been read before or whether it was cached from a previous read.

By default, both the publishing and subscribing applications run for 20 seconds and then quit. (To run them for a different number of seconds, use the -r command-line argument.) Figure 1 shows example output using the default run time and a domain ID of 13 (set with the command-line option, -d 13).

Figure 1 Example Output for Both Applications

© 2015 RTI