private ProducterHeartbeatProtect(ProducterContext context) { try { DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "ProducterHeartbeatProtect", "生产者心跳守护开始注册"); cancelSource = new CancellationTokenSource(); System.Threading.Tasks.Task.Factory.StartNew(() => { HeatbeatRun();//注册心跳 }, cancelSource.Token); DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "ProducterHeartbeatProtect", "生产者心跳守护心跳注册成功"); redislistener = new RedisNetCommandListener(ConfigHelper.RedisServer); redislistener.Name = "生产者"; redislistener.Register((channel, msg) => { RedisListenerCommand(channel, msg); }, cancelSource, context.ProducterProvider.MQPath, SystemParamConfig.Redis_Channel); DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "ProducterHeartbeatProtect", "生产者心跳redis监听注册成功"); LogHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "ProducterHeartbeatProtect", "生产者心跳守护注册成功"); } catch (Exception exp) { ErrorLogHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(), "ProducterHeartbeatProtect", "生产者心跳初始化错误", exp); throw exp; } }
private ProducterHeartbeatProtect(ProducterContext context) { try { DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(),"ProducterHeartbeatProtect", "生产者心跳守护开始注册"); cancelSource = new CancellationTokenSource(); System.Threading.Tasks.Task.Factory.StartNew(() => { HeatbeatRun();//注册心跳 }, cancelSource.Token); DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(),"ProducterHeartbeatProtect", "生产者心跳守护心跳注册成功"); redislistener = new RedisNetCommandListener(ConfigHelper.RedisServer); redislistener.Name = "生产者"; redislistener.Register((channel, msg) => { RedisListenerCommand(channel, msg); }, cancelSource, context.ProducterProvider.MQPath, SystemParamConfig.Redis_Channel); DebugHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(),"ProducterHeartbeatProtect", "生产者心跳redis监听注册成功"); LogHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(),"ProducterHeartbeatProtect", "生产者心跳守护注册成功"); } catch (Exception exp) { ErrorLogHelper.WriteLine(context.GetMQPathID(), context.GetMQPath(),"ProducterHeartbeatProtect", "生产者心跳初始化错误", exp); throw exp; } }
private DateTime GetLastUpdateTimeOfMqPath(ProducterContext context) { DB.ProducterBLL bll = new DB.ProducterBLL(); DateTime dt = DateTime.MinValue; SqlHelper.ExcuteSql(context.ProducterProvider.Config.ManageConnectString, (c) => { dt = bll.GetMqPathModel(c, context.ProducterProvider.MQPath).lastupdatetime; }); return(dt); }
/// <summary> /// 单例实例 /// </summary> /// <returns></returns> public static ProducterHeartbeatProtect Instance(ProducterContext currentcontext) { if (producterHeartbeatProtect != null) return producterHeartbeatProtect; lock (_instancelock) { producterHeartbeatProtect = new ProducterHeartbeatProtect(currentcontext); return producterHeartbeatProtect; } }
/// <summary> /// 单例实例 /// </summary> /// <returns></returns> public static ProducterHeartbeatProtect Instance(ProducterContext currentcontext) { if (producterHeartbeatProtect != null) { return(producterHeartbeatProtect); } lock (_instancelock) { producterHeartbeatProtect = new ProducterHeartbeatProtect(currentcontext); return(producterHeartbeatProtect); } }
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); } } }
public ProducterProvider() { Context = new ProducterContext(); Context.ProducterProvider = this; LoadBalance.Context = Context; }
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); } } }
private DateTime GetLastUpdateTimeOfMqPath(ProducterContext context) { DB.ProducterBLL bll = new DB.ProducterBLL(); DateTime dt = DateTime.MinValue; SqlHelper.ExcuteSql(context.ProducterProvider.Config.ManageConnectString, (c) => { dt = bll.GetMqPathModel(c, context.ProducterProvider.MQPath).lastupdatetime; }); return dt; }