Class: Kafka::Protocol::CreateTopicsRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/protocol/create_topics_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(topics:, timeout:) ⇒ CreateTopicsRequest

Returns a new instance of CreateTopicsRequest.



7
8
9
# File 'lib/kafka/protocol/create_topics_request.rb', line 7

def initialize(topics:, timeout:)
  @topics, @timeout = topics, timeout
end

Instance Method Details

#api_keyObject



11
12
13
# File 'lib/kafka/protocol/create_topics_request.rb', line 11

def api_key
  CREATE_TOPICS_API
end

#api_versionObject



15
16
17
# File 'lib/kafka/protocol/create_topics_request.rb', line 15

def api_version
  0
end

#encode(encoder) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kafka/protocol/create_topics_request.rb', line 23

def encode(encoder)
  encoder.write_array(@topics) do |topic, config|
    encoder.write_string(topic)
    encoder.write_int32(config.fetch(:num_partitions))
    encoder.write_int16(config.fetch(:replication_factor))

    # Replica assignments. We don't care.
    encoder.write_array([])

    encoder.write_array(config.fetch(:config)) do |config_name, config_value|
      config_value = config_value.to_s unless config_value.nil?
      encoder.write_string(config_name)
      encoder.write_string(config_value)
    end
  end

  # Timeout is in ms.
  encoder.write_int32(@timeout * 1000)
end

#response_classObject



19
20
21
# File 'lib/kafka/protocol/create_topics_request.rb', line 19

def response_class
  Protocol::CreateTopicsResponse
end