Ejemplo n.º 1
0
 private List<tb_messagequeue_model> GetMessagesOfPatition(tb_consumer_partition_model partition, long scanlastmqid, MQIDInfo mqidinfo, string datanodeconnectstring, PartitionIDInfo partionidinfo)
 {
     //从数据库取数据,检查数据时间,和数据状态,无问题则插入队列,并修改上一次扫描的mqid
     List<tb_messagequeue_model> messages = new List<tb_messagequeue_model>();
     SqlHelper.ExcuteSql(datanodeconnectstring, (c) =>
     {
         string tablename = PartitionRuleHelper.GetTableName(partionidinfo.TablePartition, mqidinfo.Day);
         if (exsittablenames.ContainsKey(tablename) || c.TableIsExist(tablename))
         {
             AddExsitTableNameCache(tablename);
             tb_messagequeue_dal dal = new tb_messagequeue_dal(); dal.TableName = tablename;
             messages = dal.GetMessages(c, scanlastmqid, SystemParamConfig.Consumer_ReceiveMessageQuque_EVERY_PULL_COUNT);
         }
     });
     return messages;
 }
Ejemplo n.º 2
0
 public tb_consumer_partition_model RegisterConsumerPartition(DbConn PubConn, int clientid, int partitionindex,string mqpath, long tempid)
 {
     var mqpathmodel = GetMQPath(PubConn, mqpath);
     tb_mqpath_partition_dal mqpathpartitiondal = new tb_mqpath_partition_dal();
     var mqpathpartitionmodel = mqpathpartitiondal.GetOfConsumer(PubConn, partitionindex,mqpathmodel.id);
     if (mqpathpartitionmodel == null)
         return null;
     tb_consumer_partition_dal dal = new tb_consumer_partition_dal();
     if (dal.Edit2(PubConn, new tb_consumer_partition_model() { consumerclientid = clientid, lastconsumertempid = tempid, partitionid = mqpathpartitionmodel.partitionid, partitionindex = partitionindex }) <= 0)
     {
         var partitionidinfo = PartitionRuleHelper.GetPartitionIDInfo(mqpathpartitionmodel.partitionid); var datanodename = PartitionRuleHelper.GetDataNodeName(partitionidinfo.DataNodePartition);
         long maxid = -1; DateTime serverdate = PubConn.GetServerDate(); string tablename = PartitionRuleHelper.GetTableName(partitionidinfo.TablePartition,serverdate);
         SqlHelper.ExcuteSql(this.GetDataNodeConnectString(PubConn, partitionidinfo.DataNodePartition), (c) => {
             var exist = c.TableIsExist(tablename); if (!exist) { throw new BusinessMQException(string.Format("当前数据节点{0},表{1}不存在", partitionidinfo.DataNodePartition,tablename)); }
             tb_messagequeue_dal mqdal = new tb_messagequeue_dal(); mqdal.TableName = tablename;
             maxid = mqdal.GetMaxId(c);
             if (maxid <= 0)
                 maxid = PartitionRuleHelper.GetMQID(new MQIDInfo() { AutoID=0, DataNodePartition=partitionidinfo.DataNodePartition, Day=serverdate, TablePartition=partitionidinfo.TablePartition });
         });
         dal.Add2(PubConn, new tb_consumer_partition_model() { consumerclientid = clientid, lastconsumertempid = tempid, lastmqid = maxid, partitionid = mqpathpartitionmodel.partitionid, partitionindex = partitionindex });
     }
     return dal.Get(PubConn, clientid, mqpathpartitionmodel.partitionid);
 }