use of io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary in project ksql by confluentinc.
the class ListTopicsExecutor method getTopicConsumerAndGroupCounts.
/**
* @return all topics with their associated consumerCount and consumerGroupCount
*/
private static Map<String, List<Integer>> getTopicConsumerAndGroupCounts(final KafkaConsumerGroupClient consumerGroupClient) {
final List<String> consumerGroups = consumerGroupClient.listGroups();
final Map<String, AtomicInteger> topicConsumerCount = new HashMap<>();
final Map<String, Set<String>> topicConsumerGroupCount = new HashMap<>();
for (final String group : consumerGroups) {
final Collection<ConsumerSummary> consumerSummaryList = consumerGroupClient.describeConsumerGroup(group).consumers();
for (final KafkaConsumerGroupClientImpl.ConsumerSummary summary : consumerSummaryList) {
for (final TopicPartition topicPartition : summary.partitions()) {
topicConsumerCount.computeIfAbsent(topicPartition.topic(), k -> new AtomicInteger()).incrementAndGet();
topicConsumerGroupCount.computeIfAbsent(topicPartition.topic(), k -> new HashSet<>()).add(group);
}
}
}
final HashMap<String, List<Integer>> results = new HashMap<>();
topicConsumerCount.forEach((k, v) -> {
results.computeIfAbsent(k, v1 -> new ArrayList<>()).add(v.intValue());
results.get(k).add(topicConsumerGroupCount.get(k).size());
});
return results;
}
Aggregations