Class: KafkaCli::TopicService

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka_cli/topic_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kafka_client:) ⇒ TopicService



7
8
9
# File 'lib/kafka_cli/topic_service.rb', line 7

def initialize(kafka_client:)
  @kafka_client = kafka_client
end

Instance Attribute Details

#kafka_clientObject (readonly)

Returns the value of attribute kafka_client.



5
6
7
# File 'lib/kafka_cli/topic_service.rb', line 5

def kafka_client
  @kafka_client
end

Instance Method Details

#create(topic_names: [], options: {}) ⇒ Object



23
24
25
26
27
# File 'lib/kafka_cli/topic_service.rb', line 23

def create(topic_names: [], options: {})
  kafka_client.create_topics(topic_names: topic_names,
                             partitions: options[:partitions],
                             replicas: options[:replicas])
end

#delete(topic_names: [], options: {}) ⇒ Object



29
30
31
# File 'lib/kafka_cli/topic_service.rb', line 29

def delete(topic_names: [], options: {})
  kafka_client.delete_topics(topic_names: topic_names)
end

#list(patterns: [], options: {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kafka_cli/topic_service.rb', line 11

def list(patterns: [], options: {})
  patterns = patterns.map { |pattern| Regexp.new(pattern) }

  kafka_client.topics do |topic|
    next if patterns.size.positive? && patterns.none? do |pattern|
      pattern.match?(topic[:topic_name])
    end

    puts topic
  end
end