private ConsumerInfo BuildConsumerInfo(string group, string consumerId, string topic, int queueId)
 {
     var queueCurrentOffset = _queueStore.GetQueueCurrentOffset(topic, queueId);
     var consumerInfo = new ConsumerInfo();
     consumerInfo.ConsumerGroup = group;
     consumerInfo.ConsumerId = consumerId;
     consumerInfo.Topic = topic;
     consumerInfo.QueueId = queueId;
     consumerInfo.QueueCurrentOffset = queueCurrentOffset;
     consumerInfo.ConsumedOffset = _offsetStore.GetConsumeOffset(topic, queueId, group);
     return consumerInfo;
 }
 private ConsumerInfo BuildConsumerInfo(string group, string consumerId, string topic, int queueId)
 {
     var queueCurrentOffset = _queueService.GetQueueCurrentOffset(topic, queueId);
     var consumerInfo = new ConsumerInfo();
     consumerInfo.ConsumerGroup = group;
     consumerInfo.ConsumerId = consumerId;
     consumerInfo.Topic = topic;
     consumerInfo.QueueId = queueId;
     consumerInfo.QueueMaxOffset = queueCurrentOffset;
     consumerInfo.ConsumedOffset = _offsetManager.GetQueueOffset(topic, queueId, group);
     consumerInfo.UnConsumedMessageCount = consumerInfo.QueueMaxOffset - consumerInfo.ConsumedOffset;
     return consumerInfo;
 }
Beispiel #3
0
        public void RegisterConsumer(ITcpConnection connection, string consumerId, IList<string> subscriptionTopics, IList<MessageQueueEx> consumingMessageQueues)
        {
            var connectionId = connection.RemotingEndPoint.ToAddress();

            _consumerInfoDict.AddOrUpdate(connectionId, key =>
            {
                var newConsumerInfo = new ConsumerInfo
                {
                    ConsumerId = consumerId,
                    HeartbeatInfo = new ClientHeartbeatInfo(connection) { LastHeartbeatTime = DateTime.Now },
                    SubscriptionTopics = subscriptionTopics,
                    ConsumingQueues = consumingMessageQueues
                };
                _logger.InfoFormat("Consumer registered to group, groupName: {0}, consumerId: {1}, connectionId: {2}, subscriptionTopics: {3}, consumingQueues: {4}", _groupName, consumerId, key, string.Join("|", subscriptionTopics), string.Join("|", consumingMessageQueues));
                return newConsumerInfo;
            },
            (key, existingConsumerInfo) =>
            {
                existingConsumerInfo.HeartbeatInfo.LastHeartbeatTime = DateTime.Now;

                var oldSubscriptionList = existingConsumerInfo.SubscriptionTopics.ToList();
                var newSubscriptionList = subscriptionTopics.ToList();
                if (IsStringCollectionChanged(oldSubscriptionList, newSubscriptionList))
                {
                    existingConsumerInfo.SubscriptionTopics = newSubscriptionList;
                    _logger.InfoFormat("Consumer subscriptionTopics changed. groupName: {0}, consumerId: {1}, connectionId: {2}, old: {3}, new: {4}", _groupName, consumerId, key, string.Join("|", oldSubscriptionList), string.Join("|", newSubscriptionList));
                }

                var oldConsumingQueues = existingConsumerInfo.ConsumingQueues;
                var newConsumingQueues = consumingMessageQueues;
                if (IsMessageQueueChanged(oldConsumingQueues, newConsumingQueues))
                {
                    existingConsumerInfo.ConsumingQueues = newConsumingQueues;
                    _logger.InfoFormat("Consumer consumingQueues changed. groupName: {0}, consumerId: {1}, connectionId: {2}, old: {3}, new: {4}", _groupName, consumerId, key, string.Join("|", oldConsumingQueues), string.Join("|", newConsumingQueues));
                }

                return existingConsumerInfo;
            });
        }
 private ConsumerInfo BuildConsumerInfo(string group, string consumerId, string topic, int queueId)
 {
     var consumerInfo = new ConsumerInfo();
     consumerInfo.ConsumerGroup = group;
     consumerInfo.ConsumerId = consumerId;
     consumerInfo.Topic = topic;
     consumerInfo.QueueId = queueId;
     consumerInfo.ConsumedOffset = _offsetManager.GetQueueOffset(topic, queueId, group);
     return consumerInfo;
 }