pub struct KafkaTopic { /* private fields */ }Expand description
A subscription to one Kafka topic through one consumer group.
Everything except the topic name is optional; unset options fall back to the librdkafka
defaults (this crate does not impose its own). The group can also come from
KafkaBroker::default_group; a subscription that ends up with no group at all is a
startup error, because Kafka cannot subscribe without one.
§Examples
use ruststream_rdkafka::{Assignment, Commit, KafkaTopic, StartOffset};
let topic = KafkaTopic::new("orders")
.group("orders-svc")
.start(StartOffset::Earliest)
.commit(Commit::Tracked)
.assignment(Assignment::CooperativeSticky)
.config("fetch.min.bytes", "1024");
assert_eq!(topic.topic(), "orders");Implementations§
Source§impl KafkaTopic
impl KafkaTopic
Sourcepub fn new(topic: impl Into<String>) -> Self
pub fn new(topic: impl Into<String>) -> Self
Describes a subscription to topic with librdkafka defaults for everything else.
Sourcepub fn pattern(pattern: impl Into<String>) -> Self
pub fn pattern(pattern: impl Into<String>) -> Self
Describes a subscription to every existing topic matching pattern.
The pattern is a librdkafka topic regex and must start with ^ (that anchor is how
librdkafka distinguishes a pattern from a literal name); subscribing fails with a clear
error otherwise. Topics created after the group formed are picked up on the next
metadata refresh.
§Examples
use ruststream_rdkafka::KafkaTopic;
let orders = KafkaTopic::pattern("^orders\\..*").group("orders-svc");
assert_eq!(orders.topic(), "^orders\\..*");Sourcepub fn and_topic(self, topic: impl Into<String>) -> Self
pub fn and_topic(self, topic: impl Into<String>) -> Self
Adds another topic to the same subscription: one consumer, one group, several topics.
All matched topics share the handler (and therefore its payload type). Entries starting
with ^ are librdkafka regex patterns, exactly as in pattern.
§Examples
use ruststream_rdkafka::KafkaTopic;
let both = KafkaTopic::new("orders").and_topic("cancellations");
assert_eq!(both.topic(), "orders,cancellations");Sourcepub fn group(self, group: impl Into<String>) -> Self
pub fn group(self, group: impl Into<String>) -> Self
The consumer group for this subscription, overriding
KafkaBroker::default_group.
Sourcepub fn start(self, start: StartOffset) -> Self
pub fn start(self, start: StartOffset) -> Self
Where the group starts when it has no committed offset (see StartOffset).
Sourcepub fn commit(self, commit: Commit) -> Self
pub fn commit(self, commit: Commit) -> Self
How processed deliveries are committed (see Commit).
Sourcepub fn assignment(self, assignment: Assignment) -> Self
pub fn assignment(self, assignment: Assignment) -> Self
The partition assignment strategy (see Assignment); unset means the librdkafka
default (range,roundrobin).
Sourcepub fn lane_key(self, lane_key: LaneKey) -> Self
pub fn lane_key(self, lane_key: LaneKey) -> Self
What drives keyed worker lanes for this subscription (see LaneKey); the default
lanes by the source partition, Kafka’s native ordering unit.
§Examples
use ruststream_rdkafka::{KafkaTopic, LaneKey};
// Opt into finer, per-record-key lanes: one tenant never processes concurrently,
// different tenants in one partition do.
let topic = KafkaTopic::new("orders")
.group("orders-svc")
.lane_key(LaneKey::RecordKey);Sourcepub fn partitions(self, partitions: impl IntoIterator<Item = i32>) -> Self
pub fn partitions(self, partitions: impl IntoIterator<Item = i32>) -> Self
Switches the subscription to manual partition assignment: the consumer assign()s
exactly these partitions of the topic - no group membership, no rebalancing.
Deliveries start per start; with a group also named the consumer
commits into it without joining it (so StartOffset::Committed resumes from the
group’s positions), and without one commits are off and the start offset must be
explicit. Does not combine with and_topic /
pattern (manual assignment names exact partitions of one topic) or
with Commit::Transactional.
§Examples
use ruststream_rdkafka::{KafkaTopic, StartOffset};
// An inspection reader pinned to partition 0, no group side effects.
let topic = KafkaTopic::new("orders")
.partitions([0])
.start(StartOffset::Earliest);Sourcepub fn retry(self, retry: Retry) -> Self
pub fn retry(self, retry: Retry) -> Self
What nack(true) does on this subscription (see Retry); unset keeps Kafka’s native
behavior - the offset stays unsettled and redelivers on the next fetch of the partition.
§Examples
use ruststream_rdkafka::{KafkaTopic, Retry};
let topic = KafkaTopic::new("orders")
.group("orders-svc")
.retry(Retry::Topic("orders.retry".into()))
.max_deliveries(5)
.dead_letter("orders.dlq");Sourcepub fn max_deliveries(self, max_deliveries: u32) -> Self
pub fn max_deliveries(self, max_deliveries: u32) -> Self
The poison cap: how many times a message may be delivered before nack(true) takes the
drop path instead of retrying (the original delivery counts as one). Enforced by the
retry policy - through RETRY_COUNT_HEADER
for Retry::Topic, and through an in-session counter for Retry::SeekBack.
Sourcepub fn dead_letter(self, topic: impl Into<String>) -> Self
pub fn dead_letter(self, topic: impl Into<String>) -> Self
The dead-letter topic for the drop path: nack(false) and an exhausted retry republish
the message there (stamped with the kafka-dlq-source-* headers), then settle. Without
it the drop path just settles.
Trait Implementations§
Source§impl Clone for KafkaTopic
impl Clone for KafkaTopic
Source§fn clone(&self) -> KafkaTopic
fn clone(&self) -> KafkaTopic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KafkaTopic
impl Debug for KafkaTopic
Source§impl SubscriptionSource<KafkaBroker> for KafkaTopic
impl SubscriptionSource<KafkaBroker> for KafkaTopic
Source§type Subscriber = KafkaSubscriber
type Subscriber = KafkaSubscriber
Source§async fn subscribe(
self,
broker: &KafkaBroker,
) -> Result<Self::Subscriber, KafkaError>
async fn subscribe( self, broker: &KafkaBroker, ) -> Result<Self::Subscriber, KafkaError>
Source§impl SubscriptionSource<KafkaTestBroker> for KafkaTopic
Available on crate feature testing only.
impl SubscriptionSource<KafkaTestBroker> for KafkaTopic
testing only.