Class KafkaUtils

java.lang.Object
org.nuxeo.lib.stream.log.kafka.KafkaUtils
All Implemented Interfaces:
AutoCloseable

public class KafkaUtils extends Object implements AutoCloseable
Misc Kafka Utils
Since:
9.3
  • Field Details

    • BOOTSTRAP_SERVERS_PROP

      public static final String BOOTSTRAP_SERVERS_PROP
      See Also:
    • DEFAULT_BOOTSTRAP_SERVERS

      public static final String DEFAULT_BOOTSTRAP_SERVERS
      See Also:
    • 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:
    • ADMIN_CLIENT_CLOSE_TIMEOUT_S

      protected static final long ADMIN_CLIENT_CLOSE_TIMEOUT_S
      See Also:
  • Constructor Details

    • KafkaUtils

      public KafkaUtils()
    • KafkaUtils

      public KafkaUtils(Properties adminProperties)
  • Method Details

    • getDefaultAdminProperties

      public static Properties getDefaultAdminProperties()
    • getBootstrapServers

      public static String getBootstrapServers()
    • kafkaDetected

      public static boolean kafkaDetected()
    • rangeAssignments

      public static List<List<LogPartition>> rangeAssignments(int threads, Map<String,Integer> streams)
    • roundRobinAssignments

      public static List<List<LogPartition>> roundRobinAssignments(int threads, Map<String,Integer> streams)
    • 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()
    • listConsumers

      public List<String> listConsumers(String topic)
    • getConsumerTopics

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

      public List<String> listAllConsumers()
    • getNumberOfPartitions

      public int getNumberOfPartitions(String topic)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • 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