Skip to main content

proxy

Function proxy 

Source
pub async fn proxy<F, B, C>(
    frontend: &mut F,
    backend: &mut B,
    capture: Option<&mut C>,
) -> Result<(), Error>
Expand description

Run a bidirectional message proxy between frontend and backend sockets.

Messages are forwarded in both directions:

  • Frontend → Backend
  • Backend → Frontend

An optional capture socket receives copies of all messages for monitoring.

§Parameters

  • frontend: Socket facing clients/publishers
  • backend: Socket facing workers/subscribers
  • capture: Optional socket to receive message copies

§Patterns

  • PUB-SUB: XSUB (frontend) ←→ XPUB (backend)
  • REQ-REP: ROUTER (frontend) ←→ DEALER (backend)
  • PUSH-PULL: PULL (frontend) ←→ PUSH (backend)

§Blocking

This function runs forever, forwarding messages until an error occurs.

§Errors

Returns an error if a socket operation fails.

§Example

use monocoque_zmtp::proxy::{proxy, ProxySocket};
use monocoque_zmtp::xsub::XSubSocket;
use monocoque_zmtp::xpub::XPubSocket;

#[compio::main]
async fn main() -> std::io::Result<()> {
    let mut frontend = XSubSocket::bind("127.0.0.1:5555").await?;
    let mut backend = XPubSocket::bind("127.0.0.1:5556").await?;

    proxy(&mut frontend, &mut backend, None).await
}