pub type Publisher = Endpoint<Pub>;Expand description
The publishing half of Pub/Sub.
Aliased Type§
pub struct Publisher { /* private fields */ }Implementations§
Source§impl Publisher
impl Publisher
Sourcepub fn publish(
&self,
topic: &str,
payload: impl Into<Bytes>,
) -> Result<usize, Error>
pub fn publish( &self, topic: &str, payload: impl Into<Bytes>, ) -> Result<usize, Error>
Fans payload out to every subscriber whose filter is a prefix of
topic, and returns how many it was enqueued to.
Synchronous and non-blocking: publishing never waits on a subscriber.
A subscriber whose byte budget is exhausted loses this message, which is
counted in Publisher::dropped. Zero subscribers is not an error —
a publisher with no audience is the normal startup state.
Fails with Error::LimitExceeded when payload is larger than
Limits::subscriber_buffer_bytes: such a message could never be
enqueued for anyone, so reporting it beats silently dropping it for
every subscriber. It fails the same way for a topic above 256 bytes,
which a subscriber’s decoder refuses by closing its connection.
No traceparent is written unless one is propagated: see
Publisher::publish_with_trace and
0028.
Sourcepub fn publish_with_trace(
&self,
topic: &str,
payload: impl Into<Bytes>,
trace: TraceContext,
) -> Result<usize, Error>
pub fn publish_with_trace( &self, topic: &str, payload: impl Into<Bytes>, trace: TraceContext, ) -> Result<usize, Error>
Like Publisher::publish, propagating an existing trace context.
The context comes from the caller — an inbound
crate::IncomingMeta::trace, or crate::new_trace to start one.
Sourcepub fn open(&self, topic: &str) -> FanOut
pub fn open(&self, topic: &str) -> FanOut
Opens a streamed publish: one stream per matched subscriber, written chunk by chunk.
This is the fan-out for a payload that is not in memory and need not
be — a video frame read from a capture device, a file, a response body
being forwarded
(requirements/zeughaus-video.md
request 1). Publisher::publish refuses a payload above
Limits::subscriber_buffer_bytes because such a message could not be
enqueued for anybody; here that limit applies to a chunk, so the
payload has no ceiling at all.
The subscriber set is fixed at this call: a subscriber that arrives
while the payload is in flight would receive a fragment with no way to
know it, so it gets the next message instead. Zero subscribers is not
an error, exactly as for Publisher::publish. A topic above 256
bytes cannot be sent to anyone, since a subscriber’s decoder refuses
it by closing its connection: the fan-out reaches nobody and refuses
every write with Error::LimitExceeded.
Every guarantee of Publisher::publish holds per subscriber rather
than per publish: see FanOut.
Sourcepub fn open_with_trace(&self, topic: &str, trace: TraceContext) -> FanOut
pub fn open_with_trace(&self, topic: &str, trace: TraceContext) -> FanOut
Like Publisher::open, propagating an existing trace context.
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Connections currently subscribed to this publisher.
Sourcepub fn filter_count(&self) -> usize
pub fn filter_count(&self) -> usize
Filters registered on this publisher, summed over subscribers.
Sourcepub fn dropped(&self) -> u64
pub fn dropped(&self) -> u64
Messages dropped because a subscriber could not take them, summed
over topics and causes. “Something is being discarded”; for “which
signal is starving”, see Publisher::drops.
Sourcepub fn dropped_on(&self, topic: &str) -> Option<TopicDrops>
pub fn dropped_on(&self, topic: &str) -> Option<TopicDrops>
What was dropped on topic, by cause, or None if nothing was.
Maintained as the drops happen, so this is a lookup and not a scan.
The table holds at most Limits::max_sequence_scopes topics — the
same ceiling the sequencer’s per-topic table has — and a topic beyond
it counts in Publisher::dropped only.
Sourcepub fn drops(&self) -> Vec<TopicDrops>
pub fn drops(&self) -> Vec<TopicDrops>
Every topic that lost a copy, with its counts by cause.