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
impl PushFanOut
Sourcepub async fn bind(
addr: impl ToSocketAddrs,
n_workers: usize,
) -> Result<(TcpListener, Self)>
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?;
}Sourcepub async fn bind_with_options(
addr: impl ToSocketAddrs,
n_workers: usize,
options: SocketOptions,
) -> Result<(TcpListener, Self)>
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.
Sourcepub async fn accept_workers(
listener: &TcpListener,
n_workers: usize,
options: SocketOptions,
) -> Result<Self>
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.
Sourcepub async fn accept(&mut self, listener: &TcpListener) -> Result<()>
pub async fn accept(&mut self, listener: &TcpListener) -> Result<()>
Accept one more worker on listener and add it to the pool.
Sourcepub async fn send(&mut self, msg: Vec<Bytes>) -> Result<()>
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.
Auto Trait Implementations§
impl !RefUnwindSafe for PushFanOut
impl !Send for PushFanOut
impl !Sync for PushFanOut
impl Freeze for PushFanOut
impl Unpin for PushFanOut
impl UnsafeUnpin for PushFanOut
impl UnwindSafe for PushFanOut
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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