Esempio n. 1
0
        /// <summary>
        /// 加载配置
        /// </summary>
        /// <param name="manageconnectstring"></param>
        public static void LoadConfig(string manageconnectstring)
        {
            try
            {
                List<tb_config_model> configs = new List<tb_config_model>();
                SqlHelper.ExcuteSql(manageconnectstring, (c) => { configs = new DB.ConsumerBLL().GetConfig(c); });
                foreach (var c in configs)
                {
                    if (c.key.ToLower() == EnumSystemConfigKey.RedisServer.ToString().ToLower())
                    {
                        RedisServer = c.value;
                    }
                    else if (c.key.ToLower() == EnumSystemConfigKey.DebugMqpath.ToString().ToLower())
                    {
                        DebugMqpath = c.value;
                    }
                    else if (c.key.ToLower() == EnumSystemConfigKey.LogDBConnectString.ToString().ToLower())
                    {
                        LogDBConnectString = c.value;
                    }

                }
            }
            catch (Exception exp)
            {
                ErrorLogHelper.WriteLine(-1, "", "LoadConfig", "初始化系统配置表信息出错", exp);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 加载配置
 /// </summary>
 /// <param name="manageconnectstring"></param>
 public static void LoadConfig(string manageconnectstring)
 {
     try
     {
         List <tb_config_model> configs = new List <tb_config_model>();
         SqlHelper.ExcuteSql(manageconnectstring, (c) => { configs = new DB.ConsumerBLL().GetConfig(c); });
         foreach (var c in configs)
         {
             if (c.key.ToLower() == EnumSystemConfigKey.RedisServer.ToString().ToLower())
             {
                 RedisServer = c.value;
             }
             else if (c.key.ToLower() == EnumSystemConfigKey.DebugMqpath.ToString().ToLower())
             {
                 DebugMqpath = c.value;
             }
             else if (c.key.ToLower() == EnumSystemConfigKey.LogDBConnectString.ToString().ToLower())
             {
                 LogDBConnectString = c.value;
             }
         }
     }
     catch (Exception exp)
     {
         ErrorLogHelper.WriteLine(-1, "", "LoadConfig", "初始化系统配置表信息出错", exp);
     }
 }
Esempio n. 3
0
 private DateTime GetLastUpdateTimeOfMqPath()
 {
     DB.ConsumerBLL bll = new DB.ConsumerBLL(); DateTime dt = DateTime.MinValue;
     SqlHelper.ExcuteSql(Context.ConsumerProvider.Config.ManageConnectString, (c) =>
     {
         var t = bll.GetLastUpdateTimeOfMqPath(c, Context.ConsumerProvider.MQPath);
         if (t == null)
         {
             throw new BusinessMQException(string.Format("检测到队列{0}最后更新时间为null", Context.ConsumerProvider.MQPath));
         }
         dt = t.Value;
     });
     return(dt);
 }
Esempio n. 4
0
 //心跳任务
 private void HeartBeatTask()
 {
     lock (_heartbeatrunlock)
     {
         try
         {
             //更新节点心跳
             DB.ConsumerBLL bll = new DB.ConsumerBLL();
             SqlHelper.ExcuteSql(Context.ConsumerProvider.Config.ManageConnectString, (c) =>
             {
                 bll.ConsumerHeartbeat(c, Context.ConsumerInfo.ConsumerModel.tempid, Context.ConsumerInfo.ConsumerModel.consumerclientid);
             });
             DebugHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "ConsumerHeartbeatProtect-HeartBeatTask", "更新节点心跳完毕");
             //检查当前队列是否有更新,有更新则重启customer
             var lastupdatetime = GetLastUpdateTimeOfMqPath();
             if (_lastupdatetimeofmqpath < lastupdatetime || Context.IsNeedReload == true)
             {
                 Context.IsNeedReload = false;
                 DebugHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "ConsumerHeartbeatProtect-HeartBeatTask", "检测到队列更新准备重启");
                 //Context.ConsumerProvider.ReRegister();
                 Context.ConsumerProvider.Dispose();
                 MethodInfo method = typeof(ConsumerProvider).GetMethod("RegisterReceiveMQListener", BindingFlags.Instance | BindingFlags.Public);
                 method = method.MakeGenericMethod(Context.ActionInfo.ReturnType);
                 method.Invoke(Context.ConsumerProvider, new object[] { Context.ActionInfo.Action });
                 _lastupdatetimeofmqpath     = lastupdatetime;
                 redislistener.RedisServerIp = ConfigHelper.RedisServer;
                 DebugHelper.WriteLine(Context.GetMQPathID(), Context.GetMQPath(), "ConsumerHeartbeatProtect-HeartBeatTask", "检测到队列更新重启成功");
                 LogHelper.WriteLine(Context.ConsumerInfo.MQPathModel.id, Context.ConsumerInfo.MQPathModel.mqpath, "队列更新重启", "消费者检测到队列更新重启成功");
             }
         }
         catch (Exception exp)
         {
             ErrorLogHelper.WriteLine(Context.ConsumerInfo.MQPathModel.id, Context.ConsumerInfo.MQPathModel.mqpath, "HeartBeatTask", "消费者心跳循环出错", exp);
         }
     }
 }