pub struct RunningApp { /* private fields */ }Expand description
A started service, handed out by RustStream::start.
The handle owns the graceful teardown: dropping it without calling
shutdown detaches the service (dispatch tasks keep running, nothing is
drained), per the crate rule that destructors never block. The intended shape when running
beside a foreground server:
use ruststream::memory::MemoryBroker;
use ruststream::runtime::{AppInfo, RustStream};
let app = RustStream::new(AppInfo::new("svc", "0.1.0")).register_broker(MemoryBroker::new());
let running = app.start().await?;
// e.g. axum::serve(listener, router)
// .with_graceful_shutdown(running.stopping())
// .await?;
running.shutdown().awaitImplementations§
Source§impl RunningApp
impl RunningApp
Sourcepub fn stopping(&self) -> impl Future<Output = ()> + Send + 'static
pub fn stopping(&self) -> impl Future<Output = ()> + Send + 'static
Resolves when the service begins stopping on its own: a subscriber hit a fail-fast failure and tore the service down.
The future is owned ('static), so it plugs directly into another server’s graceful
shutdown (for example axum’s with_graceful_shutdown), stopping the host when the
messaging side dies. It does not resolve on an orderly shutdown call -
the caller drives that path itself.
§Cancel safety
Cancel-safe: dropping the future loses nothing; a fresh call observes the same state.
Sourcepub fn health(&self) -> HealthProbe
pub fn health(&self) -> HealthProbe
Hands out a HealthProbe: a cheap, cloneable view of the service’s lifecycle state for
a sibling task (typically an HTTP healthz endpoint).
The probe outlives shutdown and keeps reporting the terminal state
(HealthState::Stopped, or HealthState::Failed with the fail-fast diagnostic), so
an orchestrator stops routing traffic to a process whose messaging side died while
another task keeps the process alive.
§Examples
use axum::Router;
use axum::extract::State;
use axum::http::StatusCode;
use axum::routing::get;
use ruststream::memory::MemoryBroker;
use ruststream::runtime::{AppInfo, HealthProbe, RustStream};
use tokio::net::TcpListener;
async fn healthz(State(health): State<HealthProbe>) -> StatusCode {
if health.is_running() {
StatusCode::OK
} else {
StatusCode::SERVICE_UNAVAILABLE
}
}
let app =
RustStream::new(AppInfo::new("svc", "0.1.0")).register_broker(MemoryBroker::new());
let running = app.start().await?;
let routes = Router::new()
.route("/healthz", get(healthz))
.with_state(running.health());
axum::serve(TcpListener::bind("0.0.0.0:8080").await?, routes)
.with_graceful_shutdown(running.stopping())
.await?;
running.shutdown().await?;Sourcepub fn publisher<B2, S>(
&self,
token: Bound<B2, S>,
) -> impl Future<Output = Result<<S as PublishPolicy<<B2 as Broker>::Connected>>::Live, PairError>> + Send
pub fn publisher<B2, S>( &self, token: Bound<B2, S>, ) -> impl Future<Output = Result<<S as PublishPolicy<<B2 as Broker>::Connected>>::Live, PairError>> + Send
Pairs a Bound token against its broker, for sending from a
sibling task while the service runs (the third home of a publisher, next to reply
wiring and Out injection).
Sugar over Bound::live, anchored here because the handle
existing is the witness that startup connected every registered broker.
§Errors
Returns PairError when the token’s policy fails to pair.
§Examples
use ruststream::memory::prelude::*;
use serde::Serialize;
#[derive(Serialize, Outgoing)]
#[outgoing(name = "orders")]
struct Order {
id: u64,
}
let broker = MemoryBroker::new().bindable();
let egress = broker.bind(Publish);
let app = RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(broker, |_b| {});
let running = app.start().await?;
// The HTTP task owns this publisher and sends what its requests carry.
let publisher = running.publisher(egress).await?;
publisher.message(&Order { id: 7 }).publish().await?;
running.shutdown().await?;Sourcepub async fn shutdown(self) -> Result<(), RustStreamError>
pub async fn shutdown(self) -> Result<(), RustStreamError>
Shuts the service down gracefully.
Runs the on_shutdown hooks, stops the dispatch loops, drains in-flight handlers and
post-settle continuations (bounded by the configured shutdown timeout), shuts the brokers
down in reverse registration order, then runs the after_shutdown hooks.
§Errors
Returns RustStreamError if a dispatch task panicked, a broker failed to shut down, or
the service had already torn itself down on a fail-fast failure (surfaced as
RustStreamError::Dispatch so the operator sees a non-zero exit, not a silent stop).
A failure does not cut the teardown short: every broker is still shut down and the
after_shutdown hooks still run before the first failure is returned.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RunningApp
impl !Sync for RunningApp
impl !UnwindSafe for RunningApp
impl Freeze for RunningApp
impl Send for RunningApp
impl Unpin for RunningApp
impl UnsafeUnpin for RunningApp
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 more