Skip to main content

PushFanOut

Struct PushFanOut 

Source
pub struct PushFanOut { /* private fields */ }
Expand description

A PUSH endpoint that distributes messages across a pool of PULL workers.

Create one with bind, or bind a listener yourself and call accept_workers when you need the bound port before the workers connect (the bench peer does this to print its port).

Implementations§

Source§

impl PushFanOut

Source

pub async fn bind( addr: impl ToSocketAddrs, n_workers: usize, ) -> Result<(TcpListener, Self)>

Bind to addr, accept n_workers PULL connections, and return the listener alongside the ready fan-out socket.

The listener is returned so the caller can keep accepting late workers with accept if it wants to grow the pool.

§Example
use monocoque::zmq::PushFanOut;
use bytes::Bytes;

let (_listener, mut vent) = PushFanOut::bind("127.0.0.1:5557", 4).await?;
for i in 0..100 {
    vent.send(vec![Bytes::from(format!("task-{i}"))]).await?;
}
Source

pub async fn bind_with_options( addr: impl ToSocketAddrs, n_workers: usize, options: SocketOptions, ) -> Result<(TcpListener, Self)>

Like bind but applies options to every worker connection.

Source

pub async fn accept_workers( listener: &TcpListener, n_workers: usize, options: SocketOptions, ) -> Result<Self>

Accept n_workers PULL connections on an already-bound listener.

Useful when the bound address must be read (and announced) before the workers are allowed to connect.

Source

pub async fn accept(&mut self, listener: &TcpListener) -> Result<()>

Accept one more worker on listener and add it to the pool.

Source

pub fn len(&self) -> usize

Number of workers currently in the pool.

Source

pub fn is_empty(&self) -> bool

True when no workers remain.

Source

pub async fn send(&mut self, msg: Vec<Bytes>) -> Result<()>

Send one message to the next worker in round-robin order.

Workers already known to be disconnected are skipped (and dropped from the pool) before the message is handed over, so a send that fails mid-flight only fails the current call; the failed worker is routed around from the next send onward. The call only errors when no live worker remains.

The message bodies stay zero-copy (Bytes are refcounted) and the healthy path moves msg straight into the chosen worker, so it adds no per-message allocation over a plain PushSocket::send.

Source

pub async fn send_one(&mut self, frame: Bytes) -> Result<()>

Send one single-frame message to the next worker in round-robin order.

Equivalent to send(vec![frame]), but avoids the per-message multipart container allocation in single-frame hot paths.

Source

pub async fn flush(&mut self) -> Result<()>

Flush every worker’s write-coalescing buffer.

Call this after the last send in a burst when the workers were created with write coalescing enabled.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more