Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We will also make the NewTopicBuilder a first class API for constructing topics with any permutation of defaults and specific configurations. This moves the following API from the org.apache.kafka.connect.runtime package to the org.apache.kafka.clients.admin module, leaving the old one in place but deprecating it for compatibility:

Code Block
class NewTopicBuilder {

   public NewTopicBuilder(String name) {...} 

    /**
     * Specify the desired number of partitions for the topic.
     *
     * @param numPartitions the desired number of partitions; must be positive
     * @return this builder to allow methods to be chained; never null
     */
   public NewTopicBuilder partitions(int numPartitions);

   /**
    * Specify the desired replication factor for the topic.
    *
    * @param replicationFactor the desired replication factor; must be positive
    * @return this builder to allow methods to be chained; never null
    */
   public NewTopicBuilder replicationFactor(short replicationFactor); 

    /**
     * Specify that the topic should be compacted.
     *
     * @return this builder to allow methods to be chained; never null
     */
    public NewTopicBuilder compacted();

    /**
     * Specify the minimum number of in-sync replicas required for this topic.
     *
     * @param minInSyncReplicas the minimum number of in-sync replicas allowed for the topic; must be positive
     * @return this builder to allow methods to be chained; never null
     */
    public NewTopicBuilder minInSyncReplicas(short minInSyncReplicas);

    /**
     * Specify whether the broker is allowed to elect a leader that was not an in-sync replica when no ISRs
     * are available.
     *
     * @param allow true if unclean leaders can be elected, or false if they are not allowed
     * @return this builder to allow methods to be chained; never null
     */
    public NewTopicBuilder uncleanLeaderElection(boolean allow);

    /**
     * Specify the configuration properties for the topic, overwriting any previously-set properties.
     *
     * @param configs the desired topic configuration properties, or null if all existing properties should be cleared
     * @return this builder to allow methods to be chained; never null
     */
   public NewTopicBuilder config(Map<String, Object> configs);

    /**
     * Build the {@link NewTopic} representation.
     *
     * @return the topic description; never null
     */
   public NewTopic build(); 
}

This (NewTopic) is what will be passed in AdminClient#createTopics to specify the replication factors. The default values will remain the same (sentinel value of -1).

...