pub struct MultiplexedStream { /* private fields */ }Expand description
Distributes ingestion round-robin across a fixed set of ZerobusStreams.
See the module-level documentation for routing, MessageId, and
poisoning semantics.
Implementations§
Source§impl MultiplexedStream
impl MultiplexedStream
Sourcepub fn new(streams: Vec<ZerobusStream>) -> Self
pub fn new(streams: Vec<ZerobusStream>) -> Self
Creates a multiplexed stream over the given sub-streams.
§Panics
Panics if streams is empty or holds more than 64 sub-streams.
Sourcepub async fn ingest_record(
&self,
payload: impl Into<EncodedRecord>,
) -> ZerobusResult<MessageId>
pub async fn ingest_record( &self, payload: impl Into<EncodedRecord>, ) -> ZerobusResult<MessageId>
Ingests a single record into the next sub-stream (round-robin).
Returns once the record is queued; use
wait_for_message_id with the returned id
to await server acknowledgment. If the chosen sub-stream is at capacity,
this waits for it to drain rather than rerouting.
Sourcepub async fn ingest_records<I, T>(
&self,
payload: I,
) -> ZerobusResult<Option<MessageId>>
pub async fn ingest_records<I, T>( &self, payload: I, ) -> ZerobusResult<Option<MessageId>>
Ingests a batch of records into a single sub-stream (round-robin).
The whole batch lands on one sub-stream so a single returned id covers
it. Returns None for an empty batch.
Sourcepub async fn flush(&self) -> ZerobusResult<()>
pub async fn flush(&self) -> ZerobusResult<()>
Waits until every record already queued on every sub-stream is acknowledged by the server.
If a sub-stream flush fails because that sub-stream reached a terminal state, the mux is poisoned. The first flush error is returned; additional ones are logged.
Sourcepub async fn wait_for_message_id(
&self,
message_id: MessageId,
) -> ZerobusResult<()>
pub async fn wait_for_message_id( &self, message_id: MessageId, ) -> ZerobusResult<()>
Waits for server acknowledgment of the record or batch behind a
MessageId returned from ingest_record or
ingest_records.
Sourcepub async fn close(&mut self) -> ZerobusResult<()>
pub async fn close(&mut self) -> ZerobusResult<()>
Flushes and closes all sub-streams, releasing their resources.
The first flush/close error is returned (additional ones are logged);
on error, use get_unacked_records to
recover records that were never acknowledged.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns whether the mux is closed — either via close
or because a sub-stream failure poisoned it.
Sourcepub async fn get_unacked_records(
&mut self,
) -> ZerobusResult<impl Iterator<Item = EncodedRecord>>
pub async fn get_unacked_records( &mut self, ) -> ZerobusResult<impl Iterator<Item = EncodedRecord>>
Returns records that were ingested but not acknowledged.
Closes the mux first to ensure all sub-streams have reached their terminal state, so results are always complete. Any error from close is swallowed — if records can still be recovered, they will be returned.
Sourcepub async fn get_unacked_batches(&mut self) -> ZerobusResult<Vec<EncodedBatch>>
pub async fn get_unacked_batches(&mut self) -> ZerobusResult<Vec<EncodedBatch>>
Returns batches that were ingested but not acknowledged.
Closes the mux first to ensure all sub-streams have reached their terminal state, so results are always complete. Any error from close is swallowed — if records can still be recovered, they will be returned.
Trait Implementations§
Source§impl Drop for MultiplexedStream
impl Drop for MultiplexedStream
Auto Trait Implementations§
impl !Freeze for MultiplexedStream
impl !RefUnwindSafe for MultiplexedStream
impl !UnwindSafe for MultiplexedStream
impl Send for MultiplexedStream
impl Sync for MultiplexedStream
impl Unpin for MultiplexedStream
impl UnsafeUnpin for MultiplexedStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request