示例#1
0
        private void UpdatePullRequestDict(KeyValuePair <string, HashSet <string> > pair, IList <MessageQueue> messageQueues)
        {
            var topic = pair.Key;
            var toRemovePullRequestKeys = new List <string>();

            foreach (var pullRequest in _pullRequestDict.Values.Where(x => x.MessageQueue.Topic == topic))
            {
                var key = pullRequest.MessageQueue.ToString();
                if (!messageQueues.Any(x => x.ToString() == key))
                {
                    toRemovePullRequestKeys.Add(key);
                }
            }
            foreach (var pullRequestKey in toRemovePullRequestKeys)
            {
                PullRequest pullRequest;
                if (_pullRequestDict.TryRemove(pullRequestKey, out pullRequest))
                {
                    pullRequest.IsDropped = true;
                    _commitConsumeOffsetService.CommitConsumeOffset(pullRequest);
                    _logger.InfoFormat("Dropped pull request, consumerGroup: {0}, consumerId: {1}, queue: {2}, tags: {3}",
                                       _consumer.GroupName,
                                       _clientId,
                                       pullRequest.MessageQueue,
                                       string.Join("|", pullRequest.Tags));
                }
            }
            foreach (var messageQueue in messageQueues)
            {
                var         key = messageQueue.ToString();
                PullRequest exist;
                if (!_pullRequestDict.TryGetValue(key, out exist))
                {
                    var pullRequest = new PullRequest(_clientId, _consumer.GroupName, messageQueue, -1, pair.Value);
                    if (_pullRequestDict.TryAdd(key, pullRequest))
                    {
                        _pullMessageService.SchedulePullRequest(pullRequest);
                        _logger.InfoFormat("Added pull request, consumerGroup: {0}, consumerId: {1}, queue: {2}, tags: {3}",
                                           _consumer.GroupName,
                                           _clientId,
                                           pullRequest.MessageQueue,
                                           string.Join("|", pullRequest.Tags));
                    }
                }
            }
        }
示例#2
0
 public void CommitConsumeOffset(string brokerName, string topic, int queueId, long consumeOffset)
 {
     _commitConsumeOffsetService.CommitConsumeOffset(brokerName, topic, queueId, consumeOffset);
 }