View Source KafkaEx.Messages.Fetch (kafka_ex v1.0.0-rc.1)

Represents the result of a Fetch operation from Kafka.

This struct contains the fetched records along with metadata about the fetch response such as high watermark, last stable offset, and throttling information.

Field names align with Java Kafka client's FetchResponseData.PartitionData:

  • high_watermark - maximum offset available in the partition
  • last_stable_offset - last stable offset for transactions (V4+)
  • log_start_offset - earliest offset in the log (V5+)
  • preferred_read_replica - suggested replica for reading (V11+, KIP-392)
  • aborted_transactions - list of aborted transaction details (V4+)

Summary

Functions

Builds a Fetch result struct from response data.

Returns true if there are no records in the fetch response.

Filters records to only include those with offset >= the requested fetch offset.

Returns the next offset to fetch from (last_offset + 1 or high_watermark if empty).

Returns the number of records in the fetch response.

Types

@type aborted_transaction() :: %{producer_id: integer(), first_offset: integer()}
@type t() :: %KafkaEx.Messages.Fetch{
  aborted_transactions: [aborted_transaction()] | nil,
  high_watermark: non_neg_integer(),
  last_offset: non_neg_integer() | nil,
  last_stable_offset: non_neg_integer() | nil,
  log_start_offset: non_neg_integer() | nil,
  partition: non_neg_integer(),
  preferred_read_replica: integer() | nil,
  records: [KafkaEx.Messages.Fetch.Record.t()],
  throttle_time_ms: non_neg_integer() | nil,
  topic: String.t()
}

Functions

@spec build(Keyword.t()) :: t()

Builds a Fetch result struct from response data.

@spec empty?(t()) :: boolean()

Returns true if there are no records in the fetch response.

Link to this function

filter_from_offset(fetch, offset)

View Source
@spec filter_from_offset(t(), non_neg_integer()) :: t()

Filters records to only include those with offset >= the requested fetch offset.

Kafka may return full RecordBatches that include records before the requested offset. This function trims those pre-offset records, matching the behavior of the Java Kafka client.

@spec next_offset(t()) :: non_neg_integer()

Returns the next offset to fetch from (last_offset + 1 or high_watermark if empty).

@spec record_count(t()) :: non_neg_integer()

Returns the number of records in the fetch response.