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 void HeatbeatRun() { while (!cancelSource.IsCancellationRequested) { try { foreach (var context in Contexts.CopyToList()) { ProducterBLL bll = new ProducterBLL(); SqlHelper.ExcuteSql(context.ProducterProvider.Config.ManageConnectString, (c) => { context.ManageServerTime = c.GetServerDate();//重新校准时间 bll.ProducterHeartbeat(c, context.ProducterInfo.ProducterModel.tempid, context.ProducterInfo.ProducterModel.mqpathid); }); CheckMqPathUpdate(context); } } catch (Exception exp) { ErrorLogHelper.WriteLine(-1, "", "HeatbeatRun", "生产者心跳循环错误", exp); } System.Threading.Thread.Sleep(SystemParamConfig.Producter_HeatBeat_Every_Time * 1000); DebugHelper.WriteLine(-1, "", "HeatbeatRun", "生产者心跳循环一轮结束"); } }