Topic properties

When you create topics, you assign properties to them. The properties a topic can have depends on the topic type.
The following table shows properties available for each topic type.

Topic properties for topic types
Type JSON Binary String Int64 Double Time Series RecordV2

Publish values only

tick

tick

tick

tick

Don’t retain values

tick

tick

tick

tick

tick

tick

tick

Tidy on Unsubscribe

tick

tick

tick

tick

tick

tick

tick

Time series event value type

tick

Time series retained range

tick

Time series subscription range

tick

Validate values

tick

tick

tick

tick

tick

tick

tick

Schema

tick

Conflation

tick

tick

tick

tick

tick

tick

tick

Compression

tick

tick

tick

tick

tick

tick

tick

Owner

tick

tick

tick

tick

tick

tick

tick

Removal

tick

tick

tick

tick

tick

tick

tick

Persistent

tick

tick

tick

tick

tick

tick

tick

Priority

tick

tick

tick

tick

tick

tick

tick

Examples

To set the above properties in each of the SDKs, refer to the following examples:

Java and Android
final Map<String, String> properties = new HashMap<>();
properties.put(DONT_RETAIN_VALUE, "true");
properties.put(PUBLISH_VALUES_ONLY, "true");
properties.put(TIDY_ON_UNSUBSCRIBE, "true");
properties.put(PERSISTENT, "false");

session.feature(TopicControl.class).addTopic("my/topic/path",
    newTopicSpecification(TopicType.JSON).withProperties(properties));
JavaScript
const topic_properties = {
    'DONT_RETAIN_VALUE': 'true',
    'PUBLISH_VALUES_ONLY': 'true',
    'TIDY_ON_UNSUBSCRIBE': 'true',
    'PERSISTENT': 'false'
};
const specification = new diffusion.TopicSpecification(diffusion.topics.TopicType.JSON, topic_properties);

const result = await session.topics.add('my/topic/path', specification);

if (result.added) {
    console.log(`Topic "${result.topic}" has been successfully created`);
} else {
    console.log('Topic already exists.')
}
.NET
var topicProperties = new Dictionary<string, string> {
        { TopicSpecificationProperty.DontRetainValue, "true" },
        { TopicSpecificationProperty.PublishValuesOnly, "true" },
        { TopicSpecificationProperty.TidyOnUnsubscribe, "true" },
        { TopicSpecificationProperty.Persistent, "false" }
    };

var specification = Diffusion.NewSpecification(TopicType.JSON).WithProperties(topicProperties);

var result = await session.TopicControl.AddTopicAsync("my/topic/path", specification);

if (result == AddTopicResult.EXISTS)
{
    WriteLine($"Topic already exists.");
}
else
{
    WriteLine($"Topic has been successfully created.");
}
C
static int on_topic_added_with_properties(
        SESSION_T *session,
        TOPIC_ADD_RESULT_CODE result_code,
        void *context)
{
        return HANDLER_SUCCESS;
}


...


HASH_T *properties = hash_new(1);
hash_add(properties, DIFFUSION_DONT_RETAIN_VALUE, strdup("true"));
hash_add(properties, DIFFUSION_PUBLISH_VALUES_ONLY, strdup("true"));
hash_add(properties, DIFFUSION_TIDY_ON_UNSUBSCRIBE, strdup("true"));
hash_add(properties, DIFFUSION_PERSISTENT, strdup("false"));

TOPIC_SPECIFICATION_T *specification =
        topic_specification_init_with_properties(TOPIC_TYPE_JSON, properties);

ADD_TOPIC_CALLBACK_T callback = {
        .on_topic_added_with_specification = on_topic_added_with_properties
};

add_topic_from_specification(session, "my/topic/path", specification, callback);
Python
from diffusion.features.topics.details.topic_specification import TopicSpecification

specification = TopicSpecification.new_topic_specification(diffusion.datatypes.JSON) \
                                  .with_properties(DONT_RETAIN_VALUE=True,
                                                   PUBLISH_VALUES_ONLY=True,
                                                   TIDY_ON_UNSUBSCRIBE=True,
                                                   PERSISTENT=False)
await session.topics.add_topic("my/topic/path", specification)
print("Topic has been added!")
Apple
let topic_properties = [
    PTDiffusionTopicSpecification.dontRetainValuePropertyKey(): "true",
    PTDiffusionTopicSpecification.publishValuesOnlyPropertyKey(): "true",
    PTDiffusionTopicSpecification.tidyOnSubscribePropertyKey(): "true",
    PTDiffusionTopicSpecification.persistentPropertyKey(): "false"
]
let specification = PTDiffusionTopicSpecification.init(
    type: PTDiffusionTopicType.JSON,
    properties: topic_properties
)
session.topicControl.addTopic(
    withPath: "my/topic/path",
    specification: specification) { (result, error) in
        if (result == PTDiffusionAddTopicResult.exists()) {
            print("Topic already exists.")
        }
        else {
            print("Topic has been successfully created.")
        }
}