pub struct TransportLadder<S> { /* private fields */ }Expand description
An ordered set of transports backed by an offline buffer.
Rungs are tried in the order they are added, so the cheapest, most-preferred
link is added first. A send that no rung accepts is buffered in the
[Store] and replayed by flush.
Implementations§
Source§impl<S: Store> TransportLadder<S>
impl<S: Store> TransportLadder<S>
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Connects every rung, best-effort.
A rung that fails to connect is left unreachable rather than failing the whole ladder; sends simply fall through to the next rung or the buffer.
§Returns
Ok(()) once every rung has been given the chance to connect.
§Errors
This call is best-effort and currently always returns Ok(()).
Sourcepub async fn send(&mut self, topic: &str, payload: &[u8]) -> Result<Delivery>
pub async fn send(&mut self, topic: &str, payload: &[u8]) -> Result<Delivery>
Sends a payload, falling back down the rungs and then to the buffer.
If the buffer is empty, each rung is tried in order and the first to accept the message delivers it. If every rung fails, or the buffer already holds a backlog, the message is buffered to preserve order.
§Arguments
topic- the destination topic.payload- the bytes to send.
§Returns
Delivery::Sent if a rung delivered the message, or Delivery::Buffered
if it was queued for a later flush.
§Errors
Returns [Error::Io] if the message must be buffered
but the store cannot be written.
Sourcepub async fn flush(&mut self) -> Result<usize>
pub async fn flush(&mut self) -> Result<usize>
Drains the buffer across the rungs, oldest record first.
Each record is sent before it is removed, so the first record no rung can deliver halts the drain and leaves it, and everything after it, buffered in order for a later retry.
§Returns
The number of records forwarded before the buffer emptied or a rung refused one.
§Errors
Returns [Error::Io] if the store cannot be read or
written, or [Error::Codec] if a buffered record
cannot be decoded.
Sourcepub async fn buffered(&mut self) -> Result<usize>
pub async fn buffered(&mut self) -> Result<usize>
Returns how many messages are currently buffered.
Takes the ladder mutably, like the rest of its surface. Reading through a
shared borrow would hold one across the await, which would in turn oblige
every rung to be Sync rather than only Send, and that is a heavier
requirement than a transport should have to meet.
§Returns
The number of records waiting for a flush.
§Errors
Returns [Error::Io] if the store length cannot be
read.