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 the Diffusion™ server.

The client must register a stream to access topic data that has been sent from the Diffusion server. 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 the Diffusion server 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');
                    
.NET
topics.Subscribe( topic, new TopicsCompletionCallbackDefault() );
                    
Java and Android
topics.subscribe(topic_selector).whenComplete((voidResult, exception) -> {
    //Do something
});
                    
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 });
Apple
[session.topics subscribeWithTopicSelectorExpression:topic_selector
                                   completionHandler:^(NSError * const error)
{
    if (error) {
        NSLog(@"Subscribe request failed. Error: %@", error);
    } else {
        NSLog(@"Subscribe request succeeded.");
    }
}];
                    

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