Skip to main content

Application

A RustStream value names the service, holds its brokers and mounts each handler on the broker it subscribes to.

AppInfo holds the service's title and version, and AppInfo::new takes them. They name the service in its logs and in its AsyncAPI document. with_broker registers one broker, hands its closure a BrokerScope, and mounts the chain the closure returns: |b| b.include(accept).include(audit). Each handler is one more .include(..) on that chain, after the steps of the one before it. A broker the service only publishes to returns the empty chain, |b| b. A service with several brokers calls it once per broker. logger selects the logger the framework reports to, as the Logging page shows. A broker constructor does no I/O: the application connects every broker when it starts. Handlers mounted with b.include(..) decode with the default codec; with_broker_codec names another one for the whole scope. register_broker adds a broker that only publishes, with no label and no handlers. A builder function returns impl App, so its signature stays the same as layers and state are added.

Example​

#[derive(Debug, Deserialize)]
struct Order {
id: u64,
}

#[subscriber("orders")]
async fn handle(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "got order");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> RustStream {
RustStream::new(AppInfo::new("orders", "0.1.0"))
.logger(TracingLogger)
.with_broker(MemoryBroker::new(), |b| b.include(handle))
}