Class TopicBuilder

java.lang.Object
org.springframework.kafka.config.TopicBuilder

public final class TopicBuilder extends 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 Details

    • 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(Map<Integer,List<Integer>> replicaAssignments)
      Set the replica assignments.
      Parameters:
      replicaAssignments - the assignments.
      Returns:
      the builder.
      See Also:
      • NewTopic.replicasAssignments()
    • assignReplicas

      public TopicBuilder assignReplicas(int partition, List<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(Map<String,String> configProps)
      Set the configs.
      Parameters:
      configProps - the configs.
      Returns:
      the builder.
      See Also:
      • NewTopic.configs()
    • config

      public TopicBuilder config(String configName, 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(String name)
      Create a TopicBuilder with the supplied name.
      Parameters:
      name - the name.
      Returns:
      the builder.