pub struct ConsumerGroup { /* private fields */ }Expand description
Joined Kafka consumer group member.
Implementations§
Source§impl ConsumerGroup
impl ConsumerGroup
Sourcepub fn generation_id(&self) -> i32
pub fn generation_id(&self) -> i32
Returns the current group generation ID.
Sourcepub fn metadata(&self) -> ConsumerGroupMetadata
pub fn metadata(&self) -> ConsumerGroupMetadata
Snapshots the current identity for a fenced transactional offset commit.
Take a fresh snapshot after every rejoin because generation and member identity change during rebalancing.
Sourcepub fn assignments(&self) -> &[ConsumerAssignment]
pub fn assignments(&self) -> &[ConsumerAssignment]
Returns the assigned topic partitions and next offsets.
Sourcepub fn position(&self, topic: &str, partition: i32) -> Option<i64>
pub fn position(&self, topic: &str, partition: i32) -> Option<i64>
Returns the next offset for a currently assigned topic partition.
Sourcepub fn seek(&mut self, topic: &str, partition: i32, offset: i64) -> Result<()>
pub fn seek(&mut self, topic: &str, partition: i32, offset: i64) -> Result<()>
Changes the next offset for a currently assigned topic partition.
A later group rejoin restores broker-committed or configured reset offsets for the new assignment.
Sourcepub fn pause(&mut self, topic: &str, partition: i32) -> Result<()>
pub fn pause(&mut self, topic: &str, partition: i32) -> Result<()>
Pauses fetching from a currently assigned topic partition.
Pause state is retained across a rejoin when this member keeps the topic partition.
Sourcepub fn resume(&mut self, topic: &str, partition: i32) -> Result<()>
pub fn resume(&mut self, topic: &str, partition: i32) -> Result<()>
Resumes fetching from a currently assigned topic partition.
Sourcepub async fn fetch_watermarks(
&mut self,
topic: impl Into<String>,
partition: i32,
) -> Result<PartitionWatermarks>
pub async fn fetch_watermarks( &mut self, topic: impl Into<String>, partition: i32, ) -> Result<PartitionWatermarks>
Fetches the earliest and latest available offsets for a topic partition.
The partition does not need to be assigned to this group member.
Sourcepub async fn leave(self) -> Result<()>
pub async fn leave(self) -> Result<()>
Leaves the consumer group and consumes this member handle.
Stop any separately spawned ConsumerGroupHeartbeat before leaving.
Kafka receives both the broker member ID and the configured static
instance ID, so the member does not remain active until session expiry.
Sourcepub async fn poll(&mut self) -> Result<Vec<ConsumerRecord>>
pub async fn poll(&mut self) -> Result<Vec<ConsumerRecord>>
Sends a heartbeat, polls assigned partitions, and advances in-memory offsets.
Sourcepub async fn poll_with_heartbeat(
&mut self,
heartbeat: &mut ConsumerGroupHeartbeat,
) -> Result<Vec<ConsumerRecord>>
pub async fn poll_with_heartbeat( &mut self, heartbeat: &mut ConsumerGroupHeartbeat, ) -> Result<Vec<ConsumerRecord>>
Checks a background heartbeat task before polling assigned partitions.
If the background heartbeat task has completed with a group error that
requires a rejoin, this method rejoins the group before polling and
replaces the handle with a new task using the same interval. Other
background heartbeat errors are returned to the caller. A foreground
poll rejoin also replaces the stale task before this method returns.
When the task is still running, this behaves like
ConsumerGroup::poll.
Sourcepub async fn spawn_heartbeat_task(
&self,
interval: Duration,
) -> Result<ConsumerGroupHeartbeat>
pub async fn spawn_heartbeat_task( &self, interval: Duration, ) -> Result<ConsumerGroupHeartbeat>
Starts a background heartbeat task for this joined group member.
Sourcepub async fn heartbeat(&mut self) -> Result<()>
pub async fn heartbeat(&mut self) -> Result<()>
Sends an explicit heartbeat for this group member.
Sourcepub async fn commit_offsets(&mut self) -> Result<()>
pub async fn commit_offsets(&mut self) -> Result<()>
Commits the current assignment offsets to the group coordinator.