示例#1
0
 public void SendMessageAccumulateNotification(TopicAccumulateInfo topicAccumulateInfo)
 {
     try
     {
         var body = string.Format(MailBodyFormat,
             topicAccumulateInfo.Topic,
             topicAccumulateInfo.ConsumerGroup,
             topicAccumulateInfo.AccumulateCount,
             topicAccumulateInfo.OnlineConsumerCount,
             topicAccumulateInfo.ConsumeThroughput,
             topicAccumulateInfo.QueueCount);
         var message = new MailMessage();
         message.From = new MailAddress(_senderMail);
         foreach (var targetMail in _targetEmails)
         {
             message.To.Add(targetMail);
         }
         message.Subject = MailSubject;
         message.Body = body;
         message.SubjectEncoding = Encoding.UTF8;
         message.BodyEncoding = Encoding.UTF8;
         message.Priority = MailPriority.High;
         message.IsBodyHtml = true;
         _client.Send(message);
     }
     catch (Exception ex)
     {
         _logger.Error("SendMessageAccumulateNotification has exception.", ex);
     }
 }
示例#2
0
        public IList<TopicAccumulateInfo> GetTopicAccumulateInfoList(GetTopicAccumulateInfoListRequest request)
        {
            lock (_lockObj)
            {
                var returnList = new List<TopicAccumulateInfo>();
                var tempDict = new ConcurrentDictionary<string, IList<TopicConsumeInfo>>();

                foreach (var entry1 in _clusterDict)
                {
                    foreach (var entry2 in entry1.Value.BrokerGroups)
                    {
                        foreach (var entry3 in entry2.Value.Brokers)
                        {
                            if (entry3.Value.BrokerInfo.BrokerRole != (int)BrokerRole.Master)
                            {
                                continue;
                            }
                            foreach (var topicConsumeInfo in entry3.Value.TopicConsumeInfoList)
                            {
                                var key = string.Format("{0}_{1}", topicConsumeInfo.Topic, topicConsumeInfo.ConsumerGroup);
                                var list = tempDict.GetOrAdd(key, x => new List<TopicConsumeInfo>());
                                list.Add(topicConsumeInfo);
                            }
                        }
                    }
                }

                foreach (var list in tempDict.Values)
                {
                    if (list.Count == 0)
                    {
                        continue;
                    }
                    var consumeGroup = list[0].ConsumerGroup;
                    var topic = list[0].Topic;
                    var queueCount = list.Count;
                    var onlineConsumerCount = list[0].OnlineConsumerCount;
                    var accumulateCount = 0L;
                    var consumeThroughput = 0L;

                    foreach (var item in list)
                    {
                        accumulateCount += item.QueueNotConsumeCount;
                        consumeThroughput += item.ConsumeThroughput;
                    }
                    var topicAccumulateInfo = new TopicAccumulateInfo
                    {
                        ConsumerGroup = consumeGroup,
                        Topic = topic,
                        QueueCount = queueCount,
                        AccumulateCount = accumulateCount,
                        ConsumeThroughput = consumeThroughput,
                        OnlineConsumerCount = onlineConsumerCount
                    };

                    returnList.Add(topicAccumulateInfo);
                }

                returnList = returnList.Where(x => x.AccumulateCount >= request.AccumulateThreshold).ToList();

                return returnList;
            }
        }