跳到主要内容
本页尚未翻译

下面显示的是英文原文。

StartOffset

StartOffset says where a group starts on a partition with no committed offset: committed reset, earliest or latest.

A group resumes from its committed offset whenever it has a valid one. StartOffset applies only where it has none: before the group's first commit on a partition, and after retention deleted the record a committed offset pointed at. The setting is librdkafka's auto.offset.reset, written on the descriptor with start. StartOffset::Committed, the default, leaves the choice to librdkafka, which resets to the end of the log. StartOffset::Earliest starts at the oldest record the topic retains. StartOffset::Latest starts at the end of the log: only records published after the subscription opened arrive. The second case matters for a group that sat idle longer than the topic's retention: with the default it skips to the end instead of reading what is left. A position that applies on every startup, whatever the group committed, is start_at.

Example​

A new archive group reads the invoices the topic held before the group existed.

/// Archives every invoice: a new archive group starts at the oldest record the topic retains.
#[subscriber(KafkaTopic::new("ledger.invoices").start(StartOffset::Earliest))]
async fn archive(invoice: &Invoice) -> HandlerOutcome {
tracing::info!(invoice.id, "archived");
HandlerOutcome::ack()
}