Пример #1
0
        /// <summary>
        /// 处理mqtt分包回复
        /// </summary>
        /// <param name="num">机身号</param>
        /// <param name="mqttMessage">mqtt消息</param>
        private static void ProcessPacketReturn(string num, MqttMessage mqttMessage)
        {
            var packet = new MqttPackage(mqttMessage.Payload);

            if (packet.Mode != Mode.Return)
            {
                return;
            }

            var key        = packet.GetUniqueKey(num);
            var taskSetter = taskTable.Get(key);

            if (taskSetter == null)
            {
                return;
            }

            lock (taskSetter.Packages.SyncRoot)
            {
                taskSetter.Packages.Add(packet);
                if (taskSetter.Packages.IsFin == false)
                {
                    return;
                }

                taskTable.Remove(key);
                var message = taskSetter.Packages.ToMessage();
                taskSetter.SetResult(message);
            }
        }
Пример #2
0
        /// <summary>
        /// 订阅处理回调
        /// pub/devices/*
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="topicName">主题</param>
        /// <param name="message">消息</param>
        private static void OnMqttClientReturn(object sender, string topicName, MqttMessage message)
        {
            var num = topicName.Split('/').LastOrDefault();

            if (MqttPackage.IsMqttPackage(message) == true)
            {
                ProcessPacketReturn(num, message);
            }
            else
            {
                ProcessJsonReturn(num, message);
            }
        }