Example #1
0
        public ProducterInfo GetProducterInfo(DbConn PubConn, string mqpath,string productername)
        {
            ProducterInfo r = new ProducterInfo();
            tb_mqpath_dal mqpathdal = new tb_mqpath_dal();
            r.MqPathModel = mqpathdal.Get(PubConn,mqpath);
            if (r.MqPathModel == null)
                throw new BusinessMQException(string.Format("当前mqpath:{0}未在MQ中注册队列,请联系管理员注册成功后使用。",mqpath));
            tb_mqpath_partition_dal mqpathpartitiondal = new tb_mqpath_partition_dal();
            r.MqPathParitionModel = mqpathpartitiondal.GetList(PubConn,r.MqPathModel.id);
            if (r.MqPathParitionModel == null||r.MqPathParitionModel.Count==0)
                throw new BusinessMQException(string.Format("当前mqpath:{0}未在MQ中分配相应的分区,请联系管理员分配分区后使用。", mqpath));

            //注册生产者
            r.ProducterModel = this.RegisterProducter(PubConn, r.MqPathModel.id, productername);
            //获取分区相关节点
            List<int> datanodepartition = new List<int>();
            foreach (var p in r.MqPathParitionModel)
            {
                var partitionidinfo = PartitionRuleHelper.GetPartitionIDInfo(p.partitionid);
                if (!datanodepartition.Contains(partitionidinfo.DataNodePartition))
                    datanodepartition.Add(partitionidinfo.DataNodePartition);
            }
            r.DataNodeModelDic = this.GetDataNodeModelsDic(PubConn, datanodepartition);

            return r;
        }
 /// <summary>
 /// 更新生产者缓存信息
 /// </summary>
 /// <param name="productinfo"></param>
 public void Update(ProducterInfo productinfo)
 {
     lock (_operatorlock)
     {
         this.MqPathModel         = productinfo.MqPathModel;
         this.MqPathParitionModel = productinfo.MqPathParitionModel;
         this.DataNodeModelDic    = productinfo.DataNodeModelDic;
         this.LoadBalance.ClearError();
     }
 }
 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);
         }
     }
 }
Example #4
0
 /// <summary>
 /// 更新生产者缓存信息
 /// </summary>
 /// <param name="productinfo"></param>
 public void Update(ProducterInfo productinfo)
 {
     lock (_operatorlock)
     {
         this.MqPathModel = productinfo.MqPathModel;
         this.MqPathParitionModel = productinfo.MqPathParitionModel;
         this.DataNodeModelDic = productinfo.DataNodeModelDic;
         this.LoadBalance.ClearError();
     }
 }