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