示例#1
0
 public void Process()
 {
     try
     {
         logger.Debug(string.Format("ThreadNum={0}开始创建", CurrentThreadNum));
         CommodityRepository commodityRepository = new CommodityRepository();
         LuceneBulid         builder             = new LuceneBulid();
         bool isFirst   = true;
         int  pageIndex = 1;
         if (service == null)
         {
             while (!CTS.IsCancellationRequested)
             {
                 List <Commodity> commodityList;
                 commodityList = commodityRepository.QueryList(CurrentThreadNum, pageIndex, 1000);
                 if (commodityList == null || commodityList.Count == 0)
                 {
                     break;
                 }
                 else
                 {
                     builder.BuildIndex(commodityList, PathSuffix, isFirst);
                     logger.Debug(string.Format("ThreadNum={0}完成{1}条的创建", CurrentThreadNum, 1000 * pageIndex++));
                     isFirst = false;
                 }
             }
         }
         else
         {
             while (!CTS.IsCancellationRequested)
             {
                 lock (_lock)
                 {
                     //新增代码,从Redis逐行获取
                     var result = service.BlockingPopItemFromList("commodity", TimeSpan.FromSeconds(3));
                     if (string.IsNullOrEmpty(result))
                     {
                         break;
                     }
                     else
                     {
                         var commodity = JsonHelper.JsonToObj <Commodity>(result);
                         builder.InsertIndex(commodity);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         CTS.Cancel();
         logger.Error(string.Format("ThreadNum={0}出现异常", CurrentThreadNum), ex);
     }
     finally
     {
         logger.Debug(string.Format("ThreadNum={0}完成创建", CurrentThreadNum));
     }
 }
示例#2
0
        public static void GetMqttData()
        {
            Task.Run(() =>
            {
                try
                {
                    using (RedisListService service = new RedisListService())
                    {
                        while (true)
                        {
                            log.Info($"》》》》》》》》》》》》循环队列获取的消息");
                            string result = service.BlockingPopItemFromList("DuerOSControlQueue", TimeSpan.FromMinutes(10));
                            if (!string.IsNullOrEmpty(result))
                            {
                                //Console.WriteLine($"***********队列获取的消息 {result} {DateTime.Now.ToString()}");
                                log.Info($" 》》》》》》》》》》》》队列获取的消息 {result}");
                                if (result.Contains("$"))
                                {
                                    string cachekey = result.Split('$')[0];
                                    string state    = result.Split('$')[1];
                                    ChangeStateMain.DeviceStateChange(cachekey, Convert.ToBoolean(state));
                                }
                                Thread.Sleep(100);
                            }
                        }
                    };
                }
                catch (Exception ex)
                {
                    log.Info($"获取改变状态队列异常: " + ex.Message);
                    throw;
                }
            });



            //Action act = new Action(() =>
            //{
            //    while (true)
            //    {
            //        log.Info($"***********循环队列获取的消息");
            //        string result = service.BlockingPopItemFromList("BaiDuSoundControl", TimeSpan.FromHours(3));
            //        //Console.WriteLine($"***********队列获取的消息 {result} {DateTime.Now.ToString()}");
            //        log.Info($" ***********队列获取的消息 {result}");
            //        if (result.Contains("$"))
            //        {
            //            string cachekey = result.Split('$')[0];
            //            string state = result.Split('$')[1];
            //            ChangeStateMain.DeviceStateChange(cachekey, Convert.ToBoolean(state));
            //        }
            //        Thread.Sleep(100);
            //    }
            //});
            //act.EndInvoke(act.BeginInvoke(null, null));
        }