Пример #1
0
 public void InitQueue(RabbitMQServer rabbitmqServer, string queueName)
 {
     if (string.IsNullOrEmpty(queueName))
     {
         return;
     }
     while (true)
     {
         try
         {
             var imodel = rabbitmqServer.CreateChannel();
             if (imodel != null)
             {
                 imodel.QueueDeclare(queueName, true, false, false, null);
                 break;
             }
             else
             {
                 Thread.Sleep(1000);
             }
         }
         catch (Exception ex)
         {
             _log.Error(ex);
             Thread.Sleep(1000);
         }
     }
 }
Пример #2
0
        public void PushCompanyDownload(long companyId)
        {
            Company cmp   = new Company(companyId);
            string  queue = Config.QueueWaitDownloadHtml + "." + cmp.Domain;


            _publisherJob = ProducerData.Instance(Config.RabbitMQServerComment);

            RabbitMQServer rabbitMqServer = RabbitMQManager.GetRabbitMQServer(Config.RabbitMQServerComment);
            var            Chanel         = rabbitMqServer.CreateChannel();

            Chanel.QueueDeclare(queue, true, false, false, null);

            var       productAdapter = new SqlDb(QT.Entities.Server.ConnectionString);
            DataTable tblProduct;
            var       page = 1;

            do
            {
                const string query = @"SELECT     ID, DetailUrl
FROM            Product
WHERE        Company = @COmpanyID 
ORDER BY ID
OFFSET ((@Page-1)*10000) ROWS
FETCH NEXT 10000 ROWS ONLY
";
                tblProduct = productAdapter.GetTblData(query, CommandType.Text, new SqlParameter[]
                {
                    SqlDb.CreateParamteterSQL("@Page", page++, SqlDbType.Int),
                    SqlDb.CreateParamteterSQL("@CompanyID", companyId, SqlDbType.BigInt)
                });
                PushJob(tblProduct, companyId, queue);
            } while (tblProduct.Rows.Count > 0);
        }
Пример #3
0
 private JobCompanyCrawler GetJob()
 {
     try
     {
         using (var model = _rabbitmqServer.CreateChannel())
         {
             var data = model.BasicGet(ConfigCrawler.QueueCompanyFindnew, true);
             return((data == null) ? null : JobCompanyCrawler.ParseFromJson(UTF8Encoding.UTF8.GetString(data.Body)));
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         return(null);
     }
 }
Пример #4
0
 private void btnNumberMss_Click(object sender, EventArgs e)
 {
     try
     {
         RabbitMQServer rabbitMQServer = RabbitMQManager.GetRabbitMQServer("rabbitMQKeywordSuggest");
         IModel         model          = rabbitMQServer.CreateChannel();
         QueueDeclareOk result         = model.QueueDeclare("UpdateKeywordBatch.FindSuggest", true, false, false, null);
         uint           count          = result.MessageCount;
         rabbitMQServer.CloseChannel(model);
         MessageBox.Show(count.ToString());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Пример #5
0
 public void InitChanel()
 {
     while (true)
     {
         if (_model == null || _model.IsClosed)
         {
             _model = _rabbitMqServer.CreateChannel();
             if (_model == null)
             {
                 _log.Info("Sleep and try again create model RabbitMQ");
                 Thread.Sleep(3000);
             }
         }
         break;
     }
 }
Пример #6
0
 public PublisherJob(RabbitMQServer rabbitmqServer, string exchangeName, string routingKey, string queueName) : base(rabbitmqServer, exchangeName, routingKey, queueName)
 {
     while (true)
     {
         try
         {
             IModel model = rabbitmqServer.CreateChannel();
             break;
         }
         catch (Exception ex)
         {
             _log.Error(ex.Message + ex.StackTrace);
             Thread.Sleep(1000);
         }
     }
 }
Пример #7
0
        public void Start()
        {
            while (true)
            {
                try
                {
                    RabbitMQServer         rabbitMqServer = RabbitMQManager.GetRabbitMQServer(ConfigCrawler.KeyRabbitMqCrawler);
                    RabbitMQ.Client.IModel channel        = null;

                    while (channel == null)
                    {
                        channel = rabbitMqServer.CreateChannel();
                    }

                    channel.ExchangeDeclare("CrawlerProduct", "topic", true);

                    channel.QueueDeclare(ConfigCrawler.QueueErrorCrawler, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueErrorCrawler, ConfigCrawler.ExchangeErorrCrawler, ConfigCrawler.RoutingKeyErrorCrawler);

                    channel.QueueDeclare(ConfigCrawler.QueueHistoryToSolr, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueHistoryToSolr, ConfigCrawler.ExchangeChangeProduct, ConfigCrawler.RoutingkeyChangeProduct);

                    channel.QueueDeclare(ConfigCrawler.QueueVisitedLinkFindNewToSolr, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueVisitedLinkFindNewToSolr, ConfigCrawler.ExchangeVisitedLinkFindNew, ConfigCrawler.RoutingKeyVisitedLinkFindNew);

                    channel.ExchangeDeclare(ConfigCrawler.ExchangeSessionRunning, "topic", true);
                    channel.QueueDeclare(ConfigCrawler.QueueTrackRunning, true, false, false, null);
                    channel.QueueDeclare(ConfigCrawler.QueueUpdateSessionRunning, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueUpdateSessionRunning, ConfigCrawler.ExchangeSessionRunning, ConfigCrawler.RoutingkeySessionRunning);
                    channel.QueueBind(ConfigCrawler.QueueTrackRunning, ConfigCrawler.ExchangeSessionRunning, ConfigCrawler.RoutingkeySessionRunning);

                    channel.QueueDeclare(ConfigCrawler.QueueCompanyFindnew, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueCompanyFindnew, ConfigCrawler.ExchangeCompanyFindNew, ConfigCrawler.RoutingkeyCompanyFindNew);

                    channel.QueueDeclare(ConfigCrawler.QueueCompanyReload, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueCompanyReload, ConfigCrawler.ExchangeCompanyReload, ConfigCrawler.RoutingkeyCompanyReload);

                    channel.QueueDeclare(ConfigCrawler.QueueEndSessionToSql, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueEndSessionToSql, ConfigCrawler.ExchangeEndSession, ConfigCrawler.RoutingEndSession);
                    channel.QueueDeclare(ConfigCrawler.QueueProductChangeToSql, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueProductChangeToSql, ConfigCrawler.ExchangeChangeProduct, ConfigCrawler.RoutingkeyChangeProduct);

                    channel.QueueDeclare(ConfigCrawler.QueueResetDuplicate, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueResetDuplicate, ConfigCrawler.ExchangeResetDuplicate, ConfigCrawler.RoutingkeyResetDuplicate);

                    channel.QueueDeclare(ConfigCrawler.QueueDuplicateToCache, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueDuplicateToCache, ConfigCrawler.ExchangeDuplicateProductToCache, ConfigCrawler.RoutingKeyDuplicateProductToCache);



                    channel.QueueDeclare(ConfigCrawler.QueueProductChangeToCache, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueProductChangeToCache, ConfigCrawler.ExchangeChangeProduct, ConfigCrawler.RoutingkeyChangeProduct);

                    channel.QueueDeclare(ConfigCrawler.QueueChangeDesc, true, false, false, null);
                    channel.QueueBind(ConfigCrawler.QueueChangeDesc, ConfigCrawler.ExchangeChangeDesc, ConfigCrawler.RoutingkeyChangeDesc);

                    channel.QueueDeclare(ConfigCrawler.QueueAddClassification, true, false, false, null);
                    return;
                }
                catch (Exception ex)
                {
                }
            }
        }