Topic Query
Topic Queries introduce another way for DDS developers to intelligently access data within their systems. This is a new feature introduced in Connext 5.3 that complements Content Filtered Topics and the Durability Qos policy.
Content filtered topics (CFTs) allow a DataReader to subscribe to a subset of live data from a Topic. They enable DataWriters to only publish data that is currently of interest to its matching DataReaders – saving bandwidth and complicated application logic that would have to otherwise handle filtering after reception.
The Durability Qos policy allows a DataReader to access Data that was published before the DataReader was created and joined the system.
Topic Queries complement CFTs and Durability Qos by adding the ability for a DataReader to request previously published, and even previously filtered, samples. This allows applications to scalably respond to dynamic and changing requirements within a system. Use of Topic Query does not require the DataReader to be configured with Durability Qos, nor does it require the DataReader to use Content Filtered Topics. Rather it is accessed using a new API.
DataReaders create Topic Queries with an associated filter and filter expression which selects the subset of data that the DataReader is requesting from its matching DataWriters.
For example, to create a Topic Query that will request all samples that are available in matching DataWriters’ caches where x=5
you would do the following in the C language API:
struct DDS_TopicQuerySelection selection = DDS_TopicQuerySelection_INITIALIZER; struct DDS_TopicQuery *topic_query = NULL; selection.filter_expression = “x = 5”; topic_query = DDS_DataReader_create_topic_query(reader, &selection);
The above snippet will trigger a request that is sent out on a new built-in ServiceRequest channel. All matching DataWriters that have data in their caches where x=5 will respond to the request by republishing those samples. Samples that are sent in response to Topic Queries are sent in parallel to live data, meaning that Topic Queries will not interrupt the flow of live data. Samples associated with a topic query can also be identified and read separately from live data using the new topic_query_guid field in the SampleInfo and the stream_kinds field in the ReadConditionParams.
For example, to read only samples that are in response to a Topic Query, an application could do the following using the C language API.
struct DDS_ReadConditionParams read_cond_params = DDS_READCONDITIONPARAMS_DEFAULT; /* Read only samples that are in response to a Topic Query */ read_cond_params.stream_kinds = DDS_TOPIC_QUERY_STREAM; read_cond = DDS_DataReader_create_readcondition_w_params( reader, &read_cond_params); retCode = FooDataReader_read_w_condition( FooDataReader_narrow(reader), &dataSeq, &infoSeq, DDS_LENGTH_UNLIMITED, (DDS_ReadCondition *)read_cond);
More information about Topic Query can be found in the RTI Connext DDS Core Libraries User’s Manual section on Topic Query.