pub struct Consumer { /* private fields */ }Expand description
Cheap read handle over an origin’s route table.
Clones share the underlying state without allocating any per-cursor
resources. To receive route announcements, call Self::announced; to
resolve a path into a broadcast, call Self::request.
Implementations§
Source§impl Consumer
impl Consumer
Sourcepub fn node(&self) -> NonZeroU64
pub fn node(&self) -> NonZeroU64
This origin’s Node ID, random for each run.
Sourcepub fn local(self) -> Self
pub fn local(self) -> Self
A view of the routes that entered here: every route a handle marked
Link::Peer or Link::Upstream announced is hidden from Self::announced
and never resolved by Self::request.
On a relay, this is what the relay ingests itself, from clients and in-process producers, as opposed to what its cluster peers forward. An embedder that records, republishes, or meters each broadcast once, on the node that ingests it, reads this view.
A clone whose announced also reports hidden routes:
those with a segment starting with . below the requested prefix.
Hidden routes are left out by default, so a platform can add .-named
broadcasts without them turning up in apps that list everything.
Sourcepub fn covering(self) -> Self
pub fn covering(self) -> Self
A clone whose announced also reports every route that could
serve a path in scope, not just those whose literal name matches it.
A route is a prefix that serves every path beneath it, so a route at room can
serve room/lobby.chat under a **/*.chat scope, and one above the root covers
all of it. Code that routes requests or forwards announcements needs those
routes; a session serving its peer always uses this view. Listing broadcasts does
not. Requests resolve through covering routes either way.
Sourcepub fn exclude(
&self,
prefix: impl TryInto<Path, Error: Into<Error>>,
) -> Result<Self, Error>
pub fn exclude( &self, prefix: impl TryInto<Path, Error: Into<Error>>, ) -> Result<Self, Error>
A clone that never reaches the subtree at prefix, relative to this root:
announced leaves out the routes at or beneath it and a
request for a path there fails with Error::Unauthorized. A route
announced above prefix is still reported. allowed is unchanged.
Sourcepub fn with_stats(self, session: Session) -> Self
pub fn with_stats(self, session: Session) -> Self
Attach an egress stats context: broadcasts handed out through this handle (and
any handle derived from it) are attributed to session on the publisher
(egress) side. Pass stats::Session::default to opt out.
Sourcepub fn announced(&self) -> AnnounceConsumer
pub fn announced(&self) -> AnnounceConsumer
List the paths announced in this consumer’s scope, each present or absent.
A path stays present while any route covers it, whichever identity serves it:
hold a follow to see the broadcast change. Scope, hiding and
sync behave as for routes. Drop the returned
announce::Consumer to unregister.
Sourcepub fn routes(&self) -> Routes
pub fn routes(&self) -> Routes
Every change to the routes announced in this consumer’s scope, for relays and stats: route metadata and identity replacements included.
Allocates a per-cursor coalescing buffer and replays the currently
announced routes as initial updates. Routes stay prefixes and are named
relative to this consumer’s root; its scope only decides visibility. Only routes
the scope covers are reported, unless covering asks for every
route that could serve them. Routes with a segment starting with . below a
prefix of the scope are hidden unless with_hidden opted in.
The stream also watches its scope: a client session fed by this origin asks
its peer about the scope while any stream watches it.
Drop the returned Routes to unregister.
Sourcepub fn follow(
&self,
path: impl TryInto<Path, Error: Into<Error>>,
identity: impl Into<Option<Identity>>,
) -> Result<Following, Error>
pub fn follow( &self, path: impl TryInto<Path, Error: Into<Error>>, identity: impl Into<Option<Identity>>, ) -> Result<Following, Error>
Follow the broadcast at path across the identities that serve it.
The first poll_available resolves the identity serving the path
once one is announced, retrying route churn but returning a selected handler’s refusal;
the call after a refusal waits for the serving route to change. Each later call returns
another identity taking over, or None once the path goes offline, then whatever serves
it next, even the same identity. Drop what was read from the previous broadcast then:
its tracks end with an error once its routes go. Another route of the same identity,
or another epoch of it, is not a change.
Pass an owned Identity to follow only that stream: another one taking over ends
it, and the identity is handed out again when it serves the path again. Fails with
Error::Unauthorized when this consumer’s scope can never cover the path, and with
Error::InvalidPath when it holds a *.
Sourcepub fn scope(
&self,
root: impl TryInto<Path, Error: Into<Error>>,
prefixes: &Prefixes,
) -> Result<Consumer, Error>
pub fn scope( &self, root: impl TryInto<Path, Error: Into<Error>>, prefixes: &Prefixes, ) -> Result<Consumer, Error>
Returns a consumer rooted at root and restricted to prefixes, each covering
its whole subtree.
root is relative to this consumer’s root, and prefixes are relative to
the new root. Returns Error::Unauthorized when the requested scope has
no overlap with this consumer’s scope, or Error::BoundsExceeded when
rooting the prefixes would exceed the path limit or the root holds a *.
Sourcepub fn request(
&self,
path: impl TryInto<Path, Error: Into<Error>>,
identity: impl Into<Option<Identity>>,
) -> Pending<Requesting> ⓘ
pub fn request( &self, path: impl TryInto<Path, Error: Into<Error>>, identity: impl Into<Option<Identity>>, ) -> Pending<Requesting> ⓘ
Resolve a broadcast by exact path, optionally pinning its Identity.
Returns a [kio::Pending] future, mirroring
track::Consumer::fetch_group. Every
path resolves through a front the origin’s Driver runs: the request
mints one or joins the one already serving the path, and the front picks
one identity’s route covering it and materializes it, from the broadcast itself
or from the peer that announced the route. The order is the most specific prefix,
then, within one identity, only its highest epoch is eligible, cheaper or not.
Among identities it is the preferred link (Producer::with_priority), then
the cheapest, then a broadcast published on this origin, then the shortest hop
chain, then a hash of the identity and the path, which every relay agrees on and
which spreads a pool’s paths over its hosts.
When its serving source dies or a better route of the same identity appears, including a higher epoch, the front switches to it, invisibly to subscribers: the identity promises one continuous key space. Its routes retracting with no replacement ends the broadcast, and the next request re-serves the path; tracks already in flight carry on to their own end. The broadcast also ends once no handle holds it and none of its tracks has been read for a linger, and the next request re-serves the path then too.
Another identity winning the path leaves the broadcast to its readers until its
routes go, while the next request resolves the winner on a fresh broadcast.
Consumer::routes reports that as RouteKind::Restart, and
Self::follow yields the next broadcast. A job’s exact route answering a
claim’s request continues the claim’s identity, so it is no restart.
Pass an owned Identity to refuse a different stream, both when requesting
and when an asynchronous answer resolves. None leaves lookup unpinned.
The request owns discovery for its path and retries when its covering routes change.
It reports Error::Unroutable once discovery has synced without a covering route
for the requested identity. A selected handler’s explicit refusal is returned as-is.
A broadcast resolved through a discovered route keeps
its path watched until dropped; no separate announcement watcher is needed.
A route claims capability, not inventory: resolving a covered path
succeeds optimistically, and a path that names nothing surfaces as
Error::NotFound on its tracks instead.