Class: Karafka::Cli::Topics::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/cli/topics/create.rb

Overview

Creates topics based on the routing setup and configuration

Instance Method Summary collapse

Methods included from Helpers::Colorize

#green, #grey, #red, #yellow

Instance Method Details

#callBoolean

Returns true if any topic was created, otherwise false.

Returns:

  • (Boolean)

    true if any topic was created, otherwise false



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/karafka/cli/topics/create.rb', line 9

def call
  any_created = false

  declaratives_routing_topics.each do |topic|
    name = topic.name

    if existing_topics_names.include?(name)
      puts "#{yellow('Skipping')} because topic #{name} already exists."
    else
      puts "Creating topic #{name}..."
      Admin.create_topic(
        name,
        topic.declaratives.partitions,
        topic.declaratives.replication_factor,
        topic.declaratives.details
      )
      puts "#{green('Created')} topic #{name}."
      any_created = true
    end
  end

  any_created
end