public static List getTopicPartitionsAsList()

in src/main/java/com/epam/eco/commons/kafka/KafkaUtils.java [128:149]


    public static List<TopicPartition> getTopicPartitionsAsList(
            KafkaProducer<?, ?> producer,
            Collection<String> topicNames) {
        Validate.notNull(producer, "Producer is null");
        Validate.notNull(topicNames, "Collection of topic names is null");

        if (CollectionUtils.isEmpty(topicNames)) {
            return Collections.emptyList();
        }

        List<TopicPartition> topicPartitions = new ArrayList<>();
        for (String topicName : topicNames) {
            List<PartitionInfo> partitionInfos = producer.partitionsFor(topicName);
            if (CollectionUtils.isEmpty(partitionInfos)) {
                throw new RuntimeException("Partitions metadata not found for topic " + topicName);
            }

            topicPartitions.addAll(toTopicPartitions(partitionInfos));
        }

        return topicPartitions;
    }