Method: Kafka::Client#create_topic

Defined in:
lib/kafka/client.rb

#create_topic(name, num_partitions: 1, replication_factor: 1, timeout: 30, config: {}) ⇒ nil

Creates a topic in the cluster.

Examples:

Creating a topic with log compaction

# Enable log compaction:
config = { "cleanup.policy" => "compact" }

# Create the topic:
kafka.create_topic("dns-mappings", config: config)

Parameters:

  • name (String)

    the name of the topic.

  • num_partitions (Integer) (defaults to: 1)

    the number of partitions that should be created in the topic.

  • replication_factor (Integer) (defaults to: 1)

    the replication factor of the topic.

  • timeout (Integer) (defaults to: 30)

    a duration of time to wait for the topic to be completely created.

  • config (Hash) (defaults to: {})

    topic configuration entries. See the Kafka documentation for more information.

Returns:

  • (nil)

Raises:



622
623
624
625
626
627
628
629
630
# File 'lib/kafka/client.rb', line 622

def create_topic(name, num_partitions: 1, replication_factor: 1, timeout: 30, config: {})
  @cluster.create_topic(
    name,
    num_partitions: num_partitions,
    replication_factor: replication_factor,
    timeout: timeout,
    config: config,
  )
end