class Kafka::Protocol::FetchRequest

A request to fetch messages from a given partition.

## API Specification

FetchRequest => ReplicaId MaxWaitTime MinBytes MaxBytes IsolationLevel [TopicName [Partition FetchOffset MaxBytes]]
  ReplicaId => int32
  MaxWaitTime => int32
  MinBytes => int32
  MaxBytes => int32
  IsolationLevel => int8
  TopicName => string
  Partition => int32
  FetchOffset => int64
  MaxBytes => int32

Constants

ISOLATION_READ_COMMITTED
ISOLATION_READ_UNCOMMITTED

Public Class Methods

new(max_wait_time:, min_bytes:, max_bytes:, topics:) click to toggle source

@param max_wait_time [Integer] @param min_bytes [Integer] @param topics [Hash]

# File lib/kafka/protocol/fetch_request.rb, line 28
def initialize(max_wait_time:, min_bytes:, max_bytes:, topics:)
  @replica_id = REPLICA_ID
  @max_wait_time = max_wait_time
  @min_bytes = min_bytes
  @max_bytes = max_bytes
  @topics = topics
end

Public Instance Methods

api_key() click to toggle source
# File lib/kafka/protocol/fetch_request.rb, line 36
def api_key
  FETCH_API
end
api_version() click to toggle source
# File lib/kafka/protocol/fetch_request.rb, line 40
def api_version
  4
end
encode(encoder) click to toggle source
# File lib/kafka/protocol/fetch_request.rb, line 48
def encode(encoder)
  encoder.write_int32(@replica_id)
  encoder.write_int32(@max_wait_time)
  encoder.write_int32(@min_bytes)
  encoder.write_int32(@max_bytes)
  encoder.write_int8(ISOLATION_READ_COMMITTED)

  encoder.write_array(@topics) do |topic, partitions|
    encoder.write_string(topic)

    encoder.write_array(partitions) do |partition, config|
      fetch_offset = config.fetch(:fetch_offset)
      max_bytes = config.fetch(:max_bytes)

      encoder.write_int32(partition)
      encoder.write_int64(fetch_offset)
      encoder.write_int32(max_bytes)
    end
  end
end
response_class() click to toggle source
# File lib/kafka/protocol/fetch_request.rb, line 44
def response_class
  Protocol::FetchResponse
end