Beispiel #1
0
        public void Start(out string errMsg)
        {
            errMsg = "";
            if (IsRuning)
            {
                return;
            }

            // 加载日志数据发布服务所需配置文件信息
            this.mqttParam = new MQTTParam();
            if (!LoadConfig(this.configPath, out errMsg))
            {
                return;
            }

            // 开启MQTT服务当做发布器
            mqttServer = new MQTTServer(mqttParam);
            mqttServer.Start(out errMsg);
            if (!mqttServer.IsRuning || !string.IsNullOrWhiteSpace(errMsg))
            {
                Stop();
                return;
            }

            // 开启消息队列的消费器
            queue = new BlockingCollection <PublishData>();
            task  = new Task(() =>
            {
                foreach (PublishData item in queue.GetConsumingEnumerable())
                {
                    try
                    {
                        ActionTimeout <PublishData> timeout = new ActionTimeout <PublishData>();
                        timeout.Do     = Excute;
                        bool isTimeout = timeout.DoWithTimeout(item, new TimeSpan(0, 0, 0, 5)); //只等待5秒
                        if (isTimeout)                                                          // 超时
                        {
                            GC.Collect();
                        }
                    }
                    catch
                    {
                    }
                }
            }, TaskCreationOptions.LongRunning);
            task.Start();
            IsRuning = true;
        }
Beispiel #2
0
 public MQTTServer(MQTTParam mqttParam)
 {
     this.mqttParam = mqttParam;
 }