Skip to content

brokkr-broker::ws::fleet_subscribe

Rust

Consumer-facing WS subscription endpoint for the live fleet stream (BROKKR-I-0028).

Mounted under /api/v1/fleet/live so it inherits the standard v1 PAK middleware. The handler then re-applies the admin check that GET /fleet uses (AuthPayload.admin) — simpler than the stack live-tail handler’s admin-or-owner rule, because a fleet record spans all agents and is admin-only.

Once upgraded, the connection forwards every WsMessage::FleetUpdate the FleetBroadcaster receives. When the subscriber lags past the broadcast capacity, RecvError::Lagged(n) is handled by simply dropping and continuing (per ADR-0008’s “a slow subscriber must not slow ingestion”). There is no per-agent gap concept: the consumer holds the latest record per agent_id, so a missed update is superseded by the next one for that agent.

pub

fn fleet_subscribe_routes(
dal: DAL,
broadcaster: Arc<FleetBroadcaster>,
) -> Router<DAL>

Build the fleet-live-subscription router. Mounted under /api/v1 by the parent so the standard PAK middleware applies; this fn adds its own auth-middleware layer too in case the router is mounted elsewhere.

Source
pub fn fleet_subscribe_routes(dal: DAL, broadcaster: Arc<FleetBroadcaster>) -> Router<DAL> {
Router::new()
.route("/api/v1/fleet/live", get(fleet_live_upgrade))
.layer(Extension(broadcaster))
.layer(from_fn_with_state(
dal,
v1_middleware::auth_middleware::<Body>,
))
// Outermost: supply the Authorization header from the WS subprotocol
// for browser clients before auth_middleware runs.
.layer(from_fn(ws_subprotocol_auth))
}
Name Type Value Description
FLEET_LIVE_SUBSCRIPTION_PATH_TEMPLATE &str "/api/v1/fleet/live" Documented path template (Axum colon-style). The realised path is /api/v1/fleet/live after the parent router mounts this branch.