19.3.4 Topic Filters

A QoS profile may contain several writer, reader and topic QoSs. Connext DDS will select a QoS based on the evaluation of a filter expression on the topic name. The filter expression is specified as an attribute in the XML QoS definition. For example:

<qos_profile name="StrictReliableCommunicationProfile">
<datawriter_qos topic_filter="A*">
		<history>
			<kind>KEEP_ALL_HISTORY_QOS</kind>
		</history>
		<reliability>
			<kind>RELIABLE_RELIABILITY_QOS</kind>
		</reliability>
	</datawriter_qos>
<datawriter_qos topic_filter="B*">
		<history>
			<kind>KEEP_ALL_HISTORY_QOS</kind>
		</history>
		<reliability>
			<kind>RELIABLE_RELIABILITY_QOS</kind>
		</reliability>
		<resource_limits>
			<max_samples>128</max_samples>
			<max_samples_per_instance>128
			</max_samples_per_instance>
			<initial_samples>128</initial_samples>
			<max_instances>1</max_instances>
			<initial_instances>1</initial_instances> 
		</resource_limits>
	</datawriter_qos>
	...
</qos_profile>

If topic_filter is not specified in a QoS, Connext DDS will assume the filter '*'. The QoSs with an explicit topic_filter attribute definition will be evaluated in order; they have precedence over a QoS without a topic_filter expression.

The topic_filter attribute is only used with the following APIs:

DomainParticipantFactory:

DomainParticipant:

Publisher:

Subscriber:

Topic:

DataWriter:

DataReader:

Note: in the Modern C++ API, use dds::core::QosProvider::<entity>_qos_w_topic_name() to obtain the Qos associated with a topic. For example:

auto reader_qos = qos_provider.extensions().datareader_qos_w_topic_name("Example Topic");
dds::sub::DataReader<Foo> reader(subscriber, topic, reader_qos);

Other APIs will ignore QoSs with a topic_filter value different than "*". A QoS Profile with QoSs using topic_filter can also inherit from other QoS Profiles. In this case, inheritance will consider the value of the topic_filter expression.

Important Note About Topic Filters

Use the topic_filter attribute with caution. In most cases, governance of QoS is improved by using discrete, named QoS profiles with no more than one of each kind of entity QoS section (datareader_qos, datawriter_qos, etc.) in each profile. If the topic_filter attribute contains a typographical error or omission, it is possible for a topic not to match the intended filter expression. This can result in, for example, the entity being silently assigned the default QoS. The topic_filter attribute may be preferred in cases where wildcards are used extensively to reduce duplication in the XML. In these cases, the resulting QoS of each entity should be independently and empirically confirmed. Tools that can help confirm an entity’s QoS are RTI Monitor and (as described in 19.3.3.5 Viewing Resolved QoS Values) the rtixmloutpututility.

© 2021 RTI