pub struct ConsumerGroup { /* private fields */ }Expand description
Kafka-style consumer group coordinator.
Manages consumer membership, partition assignment, offset tracking, and rebalancing across the group.
Implementations§
Source§impl ConsumerGroup
impl ConsumerGroup
Sourcepub fn new(
group_id: impl Into<String>,
partition_count: u32,
strategy: AssignmentStrategy,
heartbeat_timeout_ms: u64,
session_timeout_ms: u64,
) -> Self
pub fn new( group_id: impl Into<String>, partition_count: u32, strategy: AssignmentStrategy, heartbeat_timeout_ms: u64, session_timeout_ms: u64, ) -> Self
Create a new consumer group.
partition_count is the number of topic partitions to manage.
heartbeat_timeout_ms controls when a consumer is marked lagging.
session_timeout_ms controls when a consumer is evicted.
Sourcepub fn partition_count(&self) -> u32
pub fn partition_count(&self) -> u32
Return the number of partitions.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Return the current generation.
Sourcepub fn coordinator(&self) -> Option<&str>
pub fn coordinator(&self) -> Option<&str>
Return the current coordinator, if any.
Sourcepub fn strategy(&self) -> &AssignmentStrategy
pub fn strategy(&self) -> &AssignmentStrategy
Return the current assignment strategy.
Sourcepub fn set_strategy(&mut self, strategy: AssignmentStrategy)
pub fn set_strategy(&mut self, strategy: AssignmentStrategy)
Set the assignment strategy.
Sourcepub fn member_count(&self) -> usize
pub fn member_count(&self) -> usize
Number of registered members.
Sourcepub fn get_member(&self, consumer_id: &str) -> Option<&ConsumerMember>
pub fn get_member(&self, consumer_id: &str) -> Option<&ConsumerMember>
Get a member by ID.
Sourcepub fn get_offset(&self, partition: u32) -> Option<&PartitionOffset>
pub fn get_offset(&self, partition: u32) -> Option<&PartitionOffset>
Get partition offset information.
Sourcepub fn rebalance_history(&self) -> &VecDeque<RebalanceEvent>
pub fn rebalance_history(&self) -> &VecDeque<RebalanceEvent>
Return the rebalance history.
Sourcepub fn join(
&mut self,
consumer_id: impl Into<String>,
now_ms: u64,
) -> Result<(), GroupError>
pub fn join( &mut self, consumer_id: impl Into<String>, now_ms: u64, ) -> Result<(), GroupError>
Join a consumer to the group.
Returns an error if the consumer already exists. The first consumer to join becomes the coordinator.
Sourcepub fn leave(&mut self, consumer_id: &str) -> Result<(), GroupError>
pub fn leave(&mut self, consumer_id: &str) -> Result<(), GroupError>
Remove a consumer from the group.
If the removed consumer was the coordinator, elects a new one.
Sourcepub fn heartbeat(
&mut self,
consumer_id: &str,
now_ms: u64,
) -> Result<(), GroupError>
pub fn heartbeat( &mut self, consumer_id: &str, now_ms: u64, ) -> Result<(), GroupError>
Record a heartbeat from a consumer.
Sourcepub fn check_heartbeats(&mut self, now_ms: u64) -> Vec<String>
pub fn check_heartbeats(&mut self, now_ms: u64) -> Vec<String>
Check all consumers for heartbeat timeouts.
Marks consumers as Lagging if they exceed heartbeat_timeout_ms,
and evicts (marks Dead and removes partitions) those exceeding
session_timeout_ms.
Returns the IDs of consumers that were evicted.
Sourcepub fn elect_coordinator(&mut self)
pub fn elect_coordinator(&mut self)
Elect a coordinator from the active members.
Selects the lexicographically smallest active consumer ID.
Sourcepub fn commit_offset(
&mut self,
partition: u32,
offset: u64,
) -> Result<(), GroupError>
pub fn commit_offset( &mut self, partition: u32, offset: u64, ) -> Result<(), GroupError>
Commit an offset for a partition.
Sourcepub fn update_log_end_offset(
&mut self,
partition: u32,
offset: u64,
) -> Result<(), GroupError>
pub fn update_log_end_offset( &mut self, partition: u32, offset: u64, ) -> Result<(), GroupError>
Update the log-end offset for a partition (producer side).
Sourcepub fn consumer_lag(&self) -> HashMap<String, u64>
pub fn consumer_lag(&self) -> HashMap<String, u64>
Calculate per-consumer lag: sum of lags on partitions assigned to each consumer.
Sourcepub fn rebalance(&mut self, now_ms: u64) -> Result<RebalanceResult, GroupError>
pub fn rebalance(&mut self, now_ms: u64) -> Result<RebalanceResult, GroupError>
Trigger a rebalance using the current assignment strategy.
Returns the result with partition assignments and movement count.
Sourcepub fn current_assignments(&self) -> HashMap<String, Vec<u32>>
pub fn current_assignments(&self) -> HashMap<String, Vec<u32>>
Get current partition assignments as consumer_id -> partitions.
Sourcepub fn stats(&self) -> GroupStats
pub fn stats(&self) -> GroupStats
Aggregate statistics for the group.
Auto Trait Implementations§
impl Freeze for ConsumerGroup
impl RefUnwindSafe for ConsumerGroup
impl Send for ConsumerGroup
impl Sync for ConsumerGroup
impl Unpin for ConsumerGroup
impl UnsafeUnpin for ConsumerGroup
impl UnwindSafe for ConsumerGroup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.