pub struct ConsumerPresenceRegistry { /* private fields */ }Expand description
Process-local registry of consumer presence. Cheap mutex + small hashmap is the right shape: writes are O(1), reads are a single snapshot copy, and the cardinality is bounded by the operator’s worker fleet (typically dozens, not thousands).
Implementations§
Source§impl ConsumerPresenceRegistry
impl ConsumerPresenceRegistry
pub fn new() -> ConsumerPresenceRegistry
Sourcepub fn heartbeat(
&self,
queue: &str,
group: &str,
consumer: &str,
lease_count: u32,
now_ns: u64,
)
pub fn heartbeat( &self, queue: &str, group: &str, consumer: &str, lease_count: u32, now_ns: u64, )
Record or refresh a heartbeat. now_ns is taken from the
caller so tests can drive a deterministic clock and so the
runtime can reuse a wall-clock it already captured.
Sourcepub fn deregister(&self, queue: &str, group: &str, consumer: &str) -> bool
pub fn deregister(&self, queue: &str, group: &str, consumer: &str) -> bool
Explicitly drop a consumer (e.g. on graceful shutdown). Returns whether an entry was actually removed.
Sourcepub fn snapshot(&self, now_ns: u64, ttl_ms: u64) -> Vec<ConsumerPresence>
pub fn snapshot(&self, now_ns: u64, ttl_ms: u64) -> Vec<ConsumerPresence>
Full snapshot, deterministically ordered by (queue, group, consumer) so test assertions and Red UI tables both see a
stable shape.
Sourcepub fn count_active_by_group(
&self,
now_ns: u64,
ttl_ms: u64,
) -> HashMap<(String, String), u32>
pub fn count_active_by_group( &self, now_ns: u64, ttl_ms: u64, ) -> HashMap<(String, String), u32>
Active-consumer count per (queue, group). Only entries whose
derived state is Active are counted — Red UI surfaces this
as the “workers alive on this group right now” number, so
stale/expired must not inflate it.
Sourcepub fn prune_expired(&self, now_ns: u64, ttl_ms: u64) -> usize
pub fn prune_expired(&self, now_ns: u64, ttl_ms: u64) -> usize
Drop entries whose last_seen_age_ms exceeds 2 * ttl_ms.
Returns the number of entries removed. Safe to call on any
metadata-read path; not strictly required for correctness
(snapshot already classifies them as Expired), but bounds
memory after worker churn.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Total entry count (active + stale + expired). Mostly useful for tests and debug surfaces.
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for ConsumerPresenceRegistry
impl Debug for ConsumerPresenceRegistry
Source§impl Default for ConsumerPresenceRegistry
impl Default for ConsumerPresenceRegistry
Source§fn default() -> ConsumerPresenceRegistry
fn default() -> ConsumerPresenceRegistry
Auto Trait Implementations§
impl !Freeze for ConsumerPresenceRegistry
impl RefUnwindSafe for ConsumerPresenceRegistry
impl Send for ConsumerPresenceRegistry
impl Sync for ConsumerPresenceRegistry
impl Unpin for ConsumerPresenceRegistry
impl UnsafeUnpin for ConsumerPresenceRegistry
impl UnwindSafe for ConsumerPresenceRegistry
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request