public void PushChangeProduct(QT.Entities.CrawlerProduct.RabbitMQ.MsProduct product) { int count = 0; while (true) { try { _jobClient.PublishJob(new Job() { Data = product.GetArByte(), Type = 0 }, 0); break; } catch (Exception ex01) { _log.Error(typeof(MQLogChangeProduct).ToString() + ".PushChangeProduct:" + count++); Thread.Sleep(1000); } } }
protected override void OnStart(string[] args) { log.Info("Start service"); try { InitializeComponent(); cancelTokenSource = new CancellationTokenSource(); string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"]; workers = new Worker[workerCount]; rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName); QT.Moduls.LogCassandra.LogCrawler logCass = new QT.Moduls.LogCassandra.LogCrawler(); for (int i = 0; i < workerCount; i++) { log.InfoFormat("Start worker {i}", i.ToString()); var worker = new Worker(CrawlerProductLog, false, rabbitMQServer); workers[i] = worker; var token = this.cancelTokenSource.Token; Task workerTask = new Task(() => { worker.JobHandler = (updateDatafeedJob) => { try { token.ThrowIfCancellationRequested(); QT.Entities.CrawlerProduct.RabbitMQ.MsProduct mss = QT.Entities.CrawlerProduct.RabbitMQ.MsProduct.GetDataFromMessage(updateDatafeedJob.Data); logCass.LogProductToCassandra(mss.Classification, mss.Date_Update, mss.Image_Url, mss.Is_Black_Link, mss.Is_New, mss.Name, mss.Note, mss.Price, mss.Product_Id, mss.Status, mss.Summary, mss.Valid, mss.Session, mss.CompanyId, mss.Url); return(true); } catch (OperationCanceledException opc) { log.Info("End worker"); return(true); } catch (Exception ex01) { log.Info(ex01); return(true); } }; worker.Start(); }, token); workerTask.Start(); log.InfoFormat("Worker {0} started", i); } } catch (Exception ex) { log.Error("Start error", ex); throw; } }