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