rustzmq2 0.1.0

A native async Rust implementation of ZeroMQ
Documentation
// 01_req_rep_client_opts — REQ client showcasing every builder option.
//
// Identical wire behavior to 01_req_rep_client, but built via the typed
// builder so each tunable knob (HWM, timeouts, reconnect, TCP keepalive,
// ZMTP heartbeats, batch sizes, application metadata) is exercised in one
// place. Run alongside 01_req_rep_server.
use rustzmq2::prelude::*;
use rustzmq2::{PeerIdentity, ReconnectStop};
use std::error::Error;
use std::str::FromStr;
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Showcase of all the socket options available on the builder.
    let mut socket = rustzmq2::ReqSocket::builder()
        // ── Identity ──────────────────────────────────────────────────────
        .peer_identity(PeerIdentity::from_str("SomeCustomId")?)
        // ── High-water marks / timeouts ───────────────────────────────────
        .send_hwm(1000)
        .receive_hwm(1000)
        .send_timeout(Duration::from_secs(5))
        .receive_timeout(Duration::from_secs(5))
        .max_msg_size(1024 * 1024)
        // ── Connect / reconnect ───────────────────────────────────────────
        .connect_timeout(Duration::from_secs(2))
        .reconnect_interval(Duration::from_millis(100))
        .reconnect_interval_max(Duration::from_secs(30))
        .reconnect_stop(ReconnectStop::CONN_REFUSED)
        // ── Handshake / close ─────────────────────────────────────────────
        .handshake_interval(Some(Duration::from_secs(10)))
        .linger(Some(Duration::from_secs(1)))
        .immediate(false)
        // ── TCP kernel knobs ──────────────────────────────────────────────
        .tcp_send_buffer(256 * 1024)
        .tcp_receive_buffer(256 * 1024)
        .tcp_keepalive(true)
        .tcp_keepalive_idle(Duration::from_secs(60))
        .tcp_keepalive_interval(Duration::from_secs(10))
        .tcp_keepalive_count(5)
        // ── ZMTP heartbeats ───────────────────────────────────────────────
        .heartbeat_interval(Duration::from_secs(30))
        .heartbeat_timeout(Duration::from_secs(10))
        .heartbeat_ttl(Duration::from_secs(30))
        // ── Batch sizes (perf tuning) ─────────────────────────────────────
        .out_batch_size(Some(16))
        // ── Application metadata attached to ZMTP READY ───────────────────
        .metadata("App-Name", "zmq-rs-example")
        .metadata("App-Version", env!("CARGO_PKG_VERSION"))
        .build();

    socket
        .connect("tcp://127.0.0.1:5555")
        .await
        .expect("Failed to connect");
    println!("Connected to server");

    for _ in 0..10u64 {
        socket.send("Hello").await?;
        let repl = socket.recv().await?;
        println!("Received: {:?}", repl);
    }
    Ok(())
}