View Source KafkaEx.Messages.Offset.PartitionOffset (kafka_ex v1.0.0-rc.1)
This module represents Offset value for a specific partition.
Used for three Kafka offset-related APIs:
- ListOffsets API (log position queries) - uses
timestampfield, always hasoffset - OffsetFetch API (committed consumer group offsets) - uses
metadatafield, always hasoffset - OffsetCommit API (commit operation results) - only has
error_code,offsetis nil
Summary
Functions
Builds a PartitionOffset struct from response data.
Converts this PartitionOffset to an OffsetAndMetadata struct.
Types
@type error_code() :: KafkaEx.Support.Types.error_code() | atom()
@type leader_epoch() :: integer() | nil
@type metadata() :: binary() | nil
@type offset() :: KafkaEx.Support.Types.offset() | nil
@type partition() :: KafkaEx.Support.Types.partition()
@type partition_response() :: %{ :partition => partition(), :error_code => error_code(), optional(:offset) => offset(), optional(:timestamp) => timestamp(), optional(:metadata) => metadata(), optional(:leader_epoch) => leader_epoch() }
@type t() :: %KafkaEx.Messages.Offset.PartitionOffset{ error_code: error_code(), leader_epoch: leader_epoch(), metadata: metadata(), offset: offset(), partition: partition(), timestamp: timestamp() }
@type timestamp() :: KafkaEx.Support.Types.timestamp() | nil
Functions
@spec build(partition_response()) :: t()
Builds a PartitionOffset struct from response data.
Supports three different Kafka APIs:
ListOffsets API (log position queries):
- Includes
timestampwhen the offset was written - For older API versions, timestamp defaults to -1
- Always includes
offset
OffsetFetch API (committed consumer group offsets):
- Includes
metadata(consumer-supplied string) - Metadata can be empty string or nil
- Always includes
offset
OffsetCommit API (commit operation results):
- Only includes
partitionanderror_code - No offset (you already know what you committed)
- No metadata or timestamp
@spec to_offset_and_metadata(t()) :: KafkaEx.Messages.OffsetAndMetadata.t() | nil
Converts this PartitionOffset to an OffsetAndMetadata struct.
Returns nil if offset is nil (e.g., for OffsetCommit results that don't include offset).
Examples
iex> po = PartitionOffset.build(%{partition: 0, offset: 100, error_code: :no_error, metadata: "v1"})
iex> PartitionOffset.to_offset_and_metadata(po)
%OffsetAndMetadata{offset: 100, metadata: "v1", leader_epoch: nil}