View Source KafkaEx.Cluster.TopicPartition (kafka_ex v1.0.0-rc.1)
Represents a specific partition of a Kafka topic.
A TopicPartition is a simple identifier used to uniquely reference a
partition within a topic. This struct is used extensively across Kafka
operations for specifying which partition to produce to, consume from,
or manage offsets for.
Java equivalent: org.apache.kafka.common.TopicPartition
Summary
Functions
Builds a TopicPartition struct from keyword options.
Creates a TopicPartition from a tuple {topic, partition}.
Creates a new TopicPartition struct.
Converts a TopicPartition to a tuple {topic, partition}.
Types
@type t() :: %KafkaEx.Cluster.TopicPartition{ partition: non_neg_integer(), topic: String.t() }
Functions
Builds a TopicPartition struct from keyword options.
Options
:topic- (required) The topic name:partition- (required) The partition number
Examples
iex> TopicPartition.build(topic: "orders", partition: 0)
%TopicPartition{topic: "orders", partition: 0}
@spec from_tuple({String.t(), non_neg_integer()}) :: t()
Creates a TopicPartition from a tuple {topic, partition}.
Examples
iex> TopicPartition.from_tuple({"orders", 0})
%TopicPartition{topic: "orders", partition: 0}
@spec new(String.t(), non_neg_integer()) :: t()
Creates a new TopicPartition struct.
Parameters
topic- The topic name (must be a non-empty string)partition- The partition number (must be a non-negative integer)
Examples
iex> TopicPartition.new("orders", 0)
%TopicPartition{topic: "orders", partition: 0}
iex> TopicPartition.new("events", 3)
%TopicPartition{topic: "events", partition: 3}
@spec to_tuple(t()) :: {String.t(), non_neg_integer()}
Converts a TopicPartition to a tuple {topic, partition}.
This is useful for interoperability with APIs that expect tuple format.
Examples
iex> tp = TopicPartition.new("orders", 0)
iex> TopicPartition.to_tuple(tp)
{"orders", 0}