Just a second...

Subscribing to topics

Subscribe to topics with topic selectors. When topics exist that match the selections made by the client, data from those topics is sent to the client from Diffusion™ Cloud.

The client must register a stream to access topic data that has been sent from Diffusion Cloud. For more information, see Subscribing to topics.

Required permissions: select_topic and read_topic permissions for the specified topics

Subscribing to topics

A client can subscribe to a topic to receive updates that are published to the topic. If the topic has state, when the client subscribes to that topic Diffusion Cloud sends the topic state as a full value. Subsequent updates to the data on the topic are sent as deltas or as full values depending on the type of the topic and the structure of its data.

JavaScript
session.select('topic_selector');
                    
Apple
[session.topics subscribeWithTopicSelectorExpression:topic_selector
                                   completionHandler:^(NSError * const error)
{
    if (error) {
        NSLog(@"Subscribe request failed. Error: %@", error);
    } else {
        NSLog(@"Subscribe request succeeded.");
    }
}];
                    
Java and Android
topics.subscribe(topic_selector).whenComplete((voidResult, exception) -> {
    //Do something
});
                    
.NET
topics.Subscribe( topic, new TopicsCompletionCallbackDefault() );
                    
C
// Define the required callbacks elsewhere
subscribe(session, (SUBSCRIPTION_PARAMS_T) { .topic_selector = topic_selector,
                                             .on_topic_message = on_topic_message,
                                             .on_subscribe = on_subscribe });

A client can subscribe to multiple topics in a single request by using topic selectors. Topic selectors enable you to select whole branches of the topic tree or use regular expressions to select topics based on the names in the topic path.

For more information, see Topic selectors.

Unsubscribing from topics

To stop receiving updates from a topic or set of topics, unsubscribe from the topic or topics:

JavaScript
session.unsubscribe('topic_selector');
                    
Apple
[session.topics unsubscribeFromTopicSelectorExpression:topic_selector
                                     completionHandler:^(NSError * const error)
    {
        if (error) {
            NSLog(@"Unsubscribe request failed. Error: %@", error);
        } else {
            NSLog(@"Unsubscribe request succeeded.");
        }
    }];
                    
Java and Android
topics.unsubscribe(topic_selector).whenComplete((voidResult, exception) -> {
    //Do something
});
                    
.NET
topics.Unsubscribe( topic, new TopicsCompletionCallbackDefault() );
                    
C
// Define an on_unsubscribe callback elsewhere
unsubscribe(session, (UNSUBSCRIPTION_PARAMS_T) {.topic_selector = topic_selector,
                                                .on_unsubscribe = on_unsubscribe} );