Skip to main content

subscriber

Function subscriber 

Source
pub fn subscriber<Src, In, R, O, C, S, H>(
    source: Src,
    body: H,
) -> SubscriberBuilder<HandleValue<<In as Input>::Axis, R, O, C, H>, <Src as IntoSource>::Source, (Open, Open, Open, Open)>
where Src: IntoSource, In: Input + ?Sized, H: Handle<In, R, O, C, S>,
Expand description

Binds a Handle body to its subscription source; the one mounting verb of the manual path.

Every axis comes from the body’s impl Handle<..>: the input spelling (single, raw, batch, typed-headers pair), the reply type, the injections arena, the broker context and the typed application state. The chain then carries what is not in the signature - the declarative settings (workers, on_failure, start_at, …), what the body replies with and where (reply, to), the batch size (batch) and the documentation opt-out (undocumented) - and build seals the definition for include.

What the definition never carries is who publishes: a policy is a broker’s, and a definition is broker-agnostic, so the reply’s publisher is named at the mount site with .out(Reply, policy).

§Examples

use ruststream::memory::MemoryBroker;
use ruststream::prelude::*;

struct Audit;

impl Handle<Order> for Audit {
    async fn handle(&self, order: &Order, _outs: &(), _ctx: &mut Context<'_>) -> Result<(), HandlerOutcome> {
        println!("order {}", order.id);
        Ok(())
    }
}

fn app() -> RustStream {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(subscriber("orders", Audit).workers(nonzero!(4)).build());
    })
}