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

Represents a single record fetched from Kafka.

This struct aligns with Java Kafka client's ConsumerRecord class. It contains the record payload along with metadata like offset, key, timestamp, and headers.

Field names align with Java's ConsumerRecord:

  • topic - the topic name
  • partition - the partition number
  • offset - position in the Kafka partition
  • key - the record key (nullable)
  • value - the record content (nullable)
  • timestamp - the record timestamp
  • timestamp_type - :create_time or :log_append_time
  • headers - record headers (list of Header structs)
  • serialized_key_size - size of serialized key in bytes (-1 if nil)
  • serialized_value_size - size of serialized value in bytes (-1 if nil)
  • leader_epoch - the leader epoch (optional, for newer formats)

Summary

Functions

Builds a Record struct from response data.

Gets a header value by key. Returns nil if not found.

Returns true if the record has headers.

Returns true if the record has a non-nil key.

Returns true if the record has a non-nil value.

Returns a TopicPartition struct for this record.

Types

@type t() :: %KafkaEx.Messages.Fetch.Record{
  attributes: non_neg_integer() | nil,
  crc: non_neg_integer() | nil,
  headers: [KafkaEx.Messages.Header.t()] | nil,
  key: binary() | nil,
  leader_epoch: non_neg_integer() | nil,
  offset: non_neg_integer(),
  partition: non_neg_integer() | nil,
  serialized_key_size: integer() | nil,
  serialized_value_size: integer() | nil,
  timestamp: integer() | nil,
  timestamp_type: timestamp_type(),
  topic: String.t() | nil,
  value: binary() | nil
}
@type timestamp_type() :: :create_time | :log_append_time | nil

Functions

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

Builds a Record struct from response data.

@spec get_header(t(), binary()) :: binary() | nil

Gets a header value by key. Returns nil if not found.

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

Returns true if the record has headers.

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

Returns true if the record has a non-nil key.

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

Returns true if the record has a non-nil value.

@spec topic_partition(t()) :: KafkaEx.Cluster.TopicPartition.t()

Returns a TopicPartition struct for this record.