Пример #1
0
        public void Open()
        {
            try
            {
                DebugHelper.WriteLine(-1, MQPath, "Open", "生产者开始初始化");
                //初始化上下文信息
                ProducterBLL bll = new ProducterBLL();
                SqlHelper.ExcuteSql(Config.ManageConnectString, (c) =>
                {
                    Context.ProducterInfo             = bll.GetProducterInfo(c, MQPath, ProducterName);
                    Context.ProducterInfo.LoadBalance = LoadBalance;
                    Context.ManageServerTime          = c.GetServerDate();
                });
                Context.IsNeedReload         = false;
                Context.LastMQPathUpdateTime = Context.ProducterInfo.MqPathModel.lastupdatetime;

                //获取系统配置信息
                ConfigHelper.LoadConfig(Config.ManageConnectString);

                NetCommand = new RedisNetCommand(ConfigHelper.RedisServer);
                ProducterHeartbeatProtect.Instance(Context).Contexts.Add(Context);//注册上下文
                DebugHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "Open", "生产者初始化成功");
                LogHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "Open", "生产者初始化成功");
            }
            catch (Exception exp)
            {
                ErrorLogHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "Open", "生产者初始化", exp);
                throw exp;
            }
        }
 private void CheckMqPathUpdate(ProducterContext context)
 {
     lock (_contextupdatelock)
     {
         string mqpath = "";
         try
         {
             if (context.Disposeing == true)
             {
                 return;
             }
             mqpath = context.ProducterInfo.MqPathModel.mqpath;
             //检查当前队列是否有更新,有更新则重启producter
             var lastupdatetime = GetLastUpdateTimeOfMqPath(context);
             if (context.LastMQPathUpdateTime < lastupdatetime || context.IsNeedReload)
             {
                 ProducterBLL bll = new ProducterBLL(); ProducterInfo productinfo = null;
                 SqlHelper.ExcuteSql(context.ProducterProvider.Config.ManageConnectString, (c) =>
                 {
                     productinfo = bll.GetProducterInfo(c, context.ProducterProvider.MQPath, context.ProducterProvider.ProducterName);
                 });
                 context.ProducterInfo.Update(productinfo);
                 context.IsNeedReload         = false;
                 context.LastMQPathUpdateTime = lastupdatetime;
                 redislistener.RedisServerIp  = ConfigHelper.RedisServer;
             }
             //检查发送错误,错误发生超过一分钟自动重启来解决错误状态
             if (context.SendMessageErrorTime != null && (DateTime.Now - context.SendMessageErrorTime) > TimeSpan.FromSeconds(SystemParamConfig.Producter_SendError_Clear_Time))
             {
                 context.IsNeedReload = true; context.SendMessageErrorTime = null;
             }
         }
         catch (Exception exp)
         {
             ErrorLogHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "CheckMqPathUpdate", "生产者检测队列是否更新错误", exp);
         }
     }
 }