Пример #1
0
        public override void ProcessMessage(BasicDeliverEventArgs message)
        {
            long companyID = Convert.ToInt64(UTF8Encoding.UTF8.GetString(message.Body));
            int  result1   = WebMerchantCacheTool.InsertAllBranchesAndRegionsOfMerchant(companyID, _productConnectionString);
            bool result2   = WebMerchantCacheTool.InsertMerchantShortInfoToCache(companyID, _productConnectionString, _userConnectionString);

            Logger.Info(string.Format("{0} {1} \r\n", result1, result2));
            this.GetChannel().BasicAck(message.DeliveryTag, true);
        }
Пример #2
0
 protected override void OnStart(string[] args)
 {
     InitializeComponent();
     try
     {
         var rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"];
         _rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);
         _worker         = new Worker(_updateMerchantJobName, false, _rabbitMQServer);
         var workerTask = new Task(() =>
         {
             _worker.JobHandler = (job) =>
             {
                 long merchantID = 0;
                 try
                 {
                     merchantID = BitConverter.ToInt64(job.Data, 0);
                     if (merchantID == -1)
                     {
                         WebMerchantCacheTool.InsertAllMerchantShortInfoToCache(_productConnectionString, _userConnectionString);
                         WebMerchantCacheTool.InsertAllBranchesAndRegionsOfAllMerchant(_productConnectionString);
                     }
                     else
                     {
                         WebMerchantCacheTool.InsertMerchantShortInfoToCache(merchantID, _productConnectionString, _userConnectionString);
                         WebMerchantCacheTool.InsertAllBranchesAndRegionsOfMerchant(merchantID,
                                                                                    _productConnectionString);
                     }
                 }
                 catch (Exception jobHandlerEx)
                 {
                     Logger.Error("Update Merchant Error! ID: " + merchantID + jobHandlerEx);
                     return(false);
                 }
                 return(true);
             };
             _worker.Start();
         });
         workerTask.Start();
     }
     catch (Exception ex)
     {
         Logger.Error("Start error", ex);
         throw;
     }
 }