Lesson 17: Filter the updated data by using a content-filtered topic

In this lesson, you filter the updated data by using a content-filtered topic.

About this task

All the updated data in the MyTopic topic might not interest you. For example, you might want to receive notifications only for updated data in which myDoubleAttribute is in the range between [0.2 … 0.5]. To customize your notifications, you can use a content-filtered topic.

Procedure

  1. Open the TopicDiagram diagram that you created in Lesson 2: Create a ddsDiagram diagram.
  2. Add a new topic named MyContentFilteredTopic.
  3. On the Tags tab, enter the following information:
    1. Set the Kind field to CONTENT_FILTERED
    2. Set the related_topic field to MyTopic.
      This setting indicates that you want to filter the updated values for MyTopic. The type of MyContentFilteredTopic is the same as the type for MyTopic; you do not need to set the type field.
    3. Add the following expression to the expression field:
      ((myDoubleAttribute >= 0.2) AND (myDoubleAttribute <= 0.5))
    4. Click OK to close the Features window
  4. In SubscriberDiagram or in the browser, select the MyDataReader entity and open its Features window. On the Tags tab, in the topic field, replace MyTopic with MyContentFilteredTopic, and then click OK.
    Note: Alternatively, you can use MyDataReader in the SubscriberPkg_WaitSet package if you would like to try filtering data in a waitset-based scenario.
  5. Regenerate the code for the entire project and then build the entire project again. After you run MySubscribingApplication (or MySubscribingApplication_WaitSet) and MyPublishingApplication, you should see the following output.
    Note: To fit in this tutorial topic, the following sample output is formatted differently than how it displays when you do this lesson. The sample output has been formatted by inserting line breaks so that you can see the output for each line. These line breaks do not appear in your output when you do this tutorial. Each line begins with myKeyAttribute and ends with myLongSequence.
    ready to receive data
    myKeyAttribute: 2, myLongAttribute: 2, myBooleanAttribute: 0, 
    myDoubleAttribute: 0.500, myStringAttribute: message number 2, 
    myLongSequence: {2, 3, 4}
    myKeyAttribute: 3, myLongAttribute: 3, myBooleanAttribute: 1, 
    myDoubleAttribute: 0.333, myStringAttribute: message number 3, 
    myLongSequence: {3, 4, 5}
    myKeyAttribute: 4, myLongAttribute: 4, myBooleanAttribute: 0, 
    myDoubleAttribute: 0.250, myStringAttribute: message number 4, 
    myLongSequence: {4, 5, 6}
    myKeyAttribute: 5, myLongAttribute: 5, myBooleanAttribute: 1, 
    myDoubleAttribute: 0.200, myStringAttribute: message number 5, 
    myLongSequence: {5, 6, 7}

Lesson checkpoint

In this lesson, you learned how to filter the updated data by using a content-filtered topic.

In the next lesson, you will add quality of service elements.