public async Task <ServiceReply> Unsubscribe(string topic) { // Repeated fields cannot be instantiated in SerivceRequest creation; adding topic to unsubscribeTopics which is later sent to server with clientID RepeatedField <string> unsubscribeTopics = new RepeatedField <string>(); unsubscribeTopics.Add(topic); Debug.Log("Unsubscribe from topic: " + topic + " (backend) + unsubscribeRepeatedField: " + unsubscribeTopics.Count); ServiceRequest topicUnsubscription = new ServiceRequest { Topic = DEFAULT_TOPICS.SERVICES.TOPIC_SUBSCRIPTION, TopicSubscription = new TopicSubscription { ClientId = clientSpecification.Id, UnsubscribeTopics = { unsubscribeTopics } } }; var task = CallService(topicUnsubscription); ServiceReply subReply = await task; if (subReply.Error != null) { Debug.LogError("subReply Error! Error msg: " + subReply.Error.ToString()); return(null); } // removing callback function from dictionary netmqTopicDataClient.RemoveTopicDataCallback(topic); return(subReply); }
public async Task <bool> UnsubscribeTopic(string topic, Action <TopicDataRecord> callback) { if (callback == null) { Debug.LogError("UnsubscribeTopic() - callback is NULL!"); return(false); } // removing callback function for this topic from dictionary netmqTopicDataClient.RemoveTopicDataCallback(topic, callback); // check if there are any callbacks left for this topic, if not, unsubscribe from topic if (!this.netmqTopicDataClient.HasTopicCallbacks(topic)) { return(await UnsubscribeTopic(new List <string>() { topic })); } return(true); }