Class KafkaUtils

    • Field Detail

      • adminClient

        protected final org.apache.kafka.clients.admin.AdminClient adminClient
      • allConsumers

        protected volatile List<String> allConsumers
      • allConsumersTime

        protected volatile long allConsumersTime
      • ALL_CONSUMERS_CACHE_TIMEOUT_MS

        protected static final long ALL_CONSUMERS_CACHE_TIMEOUT_MS
        See Also:
        Constant Field Values
      • ADMIN_CLIENT_CLOSE_TIMEOUT_S

        protected static final long ADMIN_CLIENT_CLOSE_TIMEOUT_S
        See Also:
        Constant Field Values
    • Constructor Detail

      • KafkaUtils

        public KafkaUtils()
      • KafkaUtils

        public KafkaUtils​(Properties adminProperties)
    • Method Detail

      • getDefaultAdminProperties

        public static Properties getDefaultAdminProperties()
      • getBootstrapServers

        public static String getBootstrapServers()
      • kafkaDetected

        public static boolean kafkaDetected()
      • assignments

        protected static List<List<LogPartition>> assignments​(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor assignor,
                                                              int threads,
                                                              Map<String,​Integer> streams)
      • getPartsFor

        protected static Collection<org.apache.kafka.common.PartitionInfo> getPartsFor​(String topic,
                                                                                       int partitions)
      • createTopic

        public void createTopic​(String topic)
        Creates a topic with partitions and replications that default to broker configuration.
        Since:
        2021.33
      • createTopic

        public void createTopic​(String topic,
                                int partitions)
        Creates a topic with replication factor that defaults to broker configuration.
        Since:
        2021.33
      • createTopicWithoutReplication

        public void createTopicWithoutReplication​(String topic,
                                                  int partitions)
      • createTopic

        public void createTopic​(String topic,
                                int partitions,
                                short replicationFactor)
        Creates a topic with the given partitions and replication. Since 2021.33 partitions (or replications) below 1 defaults to broker configuration.
      • waitForTopicCreation

        protected void waitForTopicCreation​(String topic,
                                            Duration timeout)
      • topicExists

        public boolean topicExists​(String topic)
      • topicReady

        public boolean topicReady​(String topic)
      • partitions

        public int partitions​(String topic)
      • listTopics

        public Set<String> listTopics()
      • getConsumerTopics

        protected List<String> getConsumerTopics​(String group)
      • listAllConsumers

        public List<String> listAllConsumers()
      • getNumberOfPartitions

        public int getNumberOfPartitions​(String topic)
      • delete

        public boolean delete​(String topic)
      • deleteRecords

        public void deleteRecords​(String topic)
        Delete all records of a topic by moving the first offsets to end of each partition.
        Since:
        2021.43
      • deleteConsumers

        public void deleteConsumers()
        Remove all existing consumers and their committed positions. For testing purpose.
        Since:
        2021.43