class Kazoo::CLI::Topics

Public Instance Methods

create(name) click to toggle source
# File lib/kazoo/cli/topics.rb, line 18
def create(name)
  validate_class_options!

  kafka_cluster.create_topic(name, partitions: options[:partitions], replication_factor: options[:replication_factor])
end
delete(name) click to toggle source
# File lib/kazoo/cli/topics.rb, line 25
def delete(name)
  validate_class_options!

  kafka_cluster.topics.fetch(name).destroy
end
list() click to toggle source
# File lib/kazoo/cli/topics.rb, line 7
def list
  validate_class_options!

  kafka_cluster.topics.values.sort_by(&:name).each do |topic|
    $stdout.puts topic.name
  end
end
partitions(topic) click to toggle source
# File lib/kazoo/cli/topics.rb, line 32
def partitions(topic)
  validate_class_options!

  topic = kafka_cluster.topics.fetch(topic)
  topic.partitions.each do |partition|
    puts "#{partition.key}\tReplicas: #{partition.replicas.map(&:id).join(",")}\tISR: #{partition.isr.map(&:id).join(",")}"
  end
end
set_partitions(topic) click to toggle source
# File lib/kazoo/cli/topics.rb, line 44
def set_partitions(topic)
  validate_class_options!

  topic = kafka_cluster.topics.fetch(topic)
  new_partitions = options[:partitions] - topic.partitions.length
  raise "You can only add partitions to a topic, not remove them" if new_partitions <= 0

  replication_factor = options[:replication_factor] || topic.replication_factor
  topic.add_partitions(partitions: new_partitions, replication_factor: replication_factor)
end