Esempio n. 1
0
        /// <summary>
        /// 提供其他模块订阅用,当收到匹配主题以后发给传递进来的委托
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="callBack"></param>
        /// <returns></returns>
        public async Task <bool> SetSubscribe(string topic, ReceiveMsgHandle callBack)
        {
            if (!_topicCallbacks.TryAdd(topic, callBack))
            {
                return(false);
            }

            await _mqttClient.SubscribeAsync(topic);

            return(true);
        }
Esempio n. 2
0
        private bool GetTopicCallback(string topic, out ReceiveMsgHandle act)
        {
            act = null;
            var orgTpStrs = topic.Split('/');

            foreach (var pair in _topicCallbacks)
            {
                if (topicFilter.IsMatch(topic, pair.Key))
                {
                    act = pair.Value;
                    return(true);
                }
            }

            return(false);
        }