#[non_exhaustive]pub struct SubscriptionCount {
pub active: usize,
pub started: usize,
}Expand description
How many of the service’s subscriptions are consuming, as a HealthProbe reports it.
A subscription counts once, whatever its worker count. It is active from the moment its
dispatch loop starts until the loop ends: on shutdown, or when its stream ends while the
service runs (see SubscriptionEnd). Whether a service with fewer active subscriptions than
it started is healthy is the service’s own call.
§Examples
use ruststream::memory::prelude::*;
use ruststream::runtime::{HealthProbe, RustStreamError, SubscriptionCount};
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
id: u64,
}
#[subscriber("orders")]
async fn accept(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "accepted");
HandlerOutcome::ack()
}
/// Healthy while the service runs and every subscription it started still reads its queue.
fn healthy(health: &HealthProbe) -> bool {
let SubscriptionCount {
active, started, ..
} = health.subscriptions();
health.is_running() && active == started
}
pub async fn run() -> Result<(), RustStreamError> {
let app = RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
MemoryBroker::new(),
|b| {
b.include(accept);
},
);
let running = app.start().await?;
tracing::info!(healthy = healthy(&running.health()), "service started");
running.shutdown().await
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.active: usizeThe subscriptions whose dispatch loop is running.
started: usizeThe subscriptions the service started.
Trait Implementations§
Source§impl Clone for SubscriptionCount
impl Clone for SubscriptionCount
impl Copy for SubscriptionCount
Source§impl Debug for SubscriptionCount
impl Debug for SubscriptionCount
Source§impl Default for SubscriptionCount
impl Default for SubscriptionCount
impl Eq for SubscriptionCount
Source§impl PartialEq for SubscriptionCount
impl PartialEq for SubscriptionCount
impl StructuralPartialEq for SubscriptionCount
Auto Trait Implementations§
impl Freeze for SubscriptionCount
impl RefUnwindSafe for SubscriptionCount
impl Send for SubscriptionCount
impl Sync for SubscriptionCount
impl Unpin for SubscriptionCount
impl UnsafeUnpin for SubscriptionCount
impl UnwindSafe for SubscriptionCount
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
Converts
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> ⓘ
Converts
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>
Wrap the input message
T in a tonic::Request