Class TopicBuilder


  • public final class TopicBuilder
    extends java.lang.Object
    Builder for a NewTopic. Since 2.6 partitions and replicas default to Optional.empty() indicating the broker defaults will be applied.
    Since:
    2.3
    Author:
    Gary Russell
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TopicBuilder assignReplicas​(int partition, java.util.List<java.lang.Integer> replicaList)
      Add an individual replica assignment.
      org.apache.kafka.clients.admin.NewTopic build()  
      TopicBuilder compact()
      Set the TopicConfig.CLEANUP_POLICY_CONFIG to TopicConfig.CLEANUP_POLICY_COMPACT.
      TopicBuilder config​(java.lang.String configName, java.lang.String configValue)
      Set a configuration option.
      TopicBuilder configs​(java.util.Map<java.lang.String,​java.lang.String> configProps)
      Set the configs.
      static TopicBuilder name​(java.lang.String name)
      Create a TopicBuilder with the supplied name.
      TopicBuilder partitions​(int partitionCount)
      Set the number of partitions (default broker 'num.partitions').
      TopicBuilder replicas​(int replicaCount)
      Set the number of replicas (default broker 'default.replication.factor').
      TopicBuilder replicasAssignments​(java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> replicaAssignments)
      Set the replica assignments.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • partitions

        public TopicBuilder partitions​(int partitionCount)
        Set the number of partitions (default broker 'num.partitions').
        Parameters:
        partitionCount - the partitions.
        Returns:
        the builder.
      • replicas

        public TopicBuilder replicas​(int replicaCount)
        Set the number of replicas (default broker 'default.replication.factor').
        Parameters:
        replicaCount - the replicas (which will be cast to short).
        Returns:
        the builder.
      • replicasAssignments

        public TopicBuilder replicasAssignments​(java.util.Map<java.lang.Integer,​java.util.List<java.lang.Integer>> replicaAssignments)
        Set the replica assignments.
        Parameters:
        replicaAssignments - the assignments.
        Returns:
        the builder.
        See Also:
        NewTopic.replicasAssignments()
      • assignReplicas

        public TopicBuilder assignReplicas​(int partition,
                                           java.util.List<java.lang.Integer> replicaList)
        Add an individual replica assignment.
        Parameters:
        partition - the partition.
        replicaList - the replicas.
        Returns:
        the builder.
        See Also:
        NewTopic.replicasAssignments()
      • configs

        public TopicBuilder configs​(java.util.Map<java.lang.String,​java.lang.String> configProps)
        Set the configs.
        Parameters:
        configProps - the configs.
        Returns:
        the builder.
        See Also:
        NewTopic.configs()
      • config

        public TopicBuilder config​(java.lang.String configName,
                                   java.lang.String configValue)
        Set a configuration option.
        Parameters:
        configName - the name.
        configValue - the value.
        Returns:
        the builder
        See Also:
        TopicConfig
      • compact

        public TopicBuilder compact()
        Set the TopicConfig.CLEANUP_POLICY_CONFIG to TopicConfig.CLEANUP_POLICY_COMPACT.
        Returns:
        the builder.
      • build

        public org.apache.kafka.clients.admin.NewTopic build()
      • name

        public static TopicBuilder name​(java.lang.String name)
        Create a TopicBuilder with the supplied name.
        Parameters:
        name - the name.
        Returns:
        the builder.