pub trait SinkSocket: AsSocket {
    fn send(self, multipart: Multipart) -> MultipartRequest<Self> { ... }
    fn sink(self, buffer_size: usize) -> MultipartSink { ... }
}
Expand description

This trait provides the basic Sink support for ZeroMQ Sockets. It depends on AsSocket and provides the send and sink methods.

Provided Methods§

Send a single multipart message to the socket.

Example, using a Pub wrapper type
extern crate zmq;
extern crate futures;
extern crate tokio;
extern crate tokio_zmq;

use std::sync::Arc;

use futures::Future;
use tokio_zmq::{prelude::*, async_types::MultipartStream, Error, Pub, Socket};

fn main() {
    let context = Arc::new(zmq::Context::new());
    let zpub = Pub::builder(context)
        .connect("tcp://localhost:5569")
        .build()
        .unwrap();

    let msg = zmq::Message::from_slice(b"Hello").unwrap();

    let fut = zpub.send(msg.into());

    // tokio::run(fut.map(|_| ()).or_else(|e| {
    //     println!("Error: {}", e);
    //     Ok(())
    // }));
}

Send a stream of multipart messages to the socket.

It takes a buffer_size argument, which will determine how many Multiparts can be submitted into the send queue before the sink applies backpressure.

Example, using a Pub wrapper type
extern crate zmq;
extern crate futures;
extern crate tokio;
extern crate tokio_zmq;

use std::sync::Arc;

use futures::{Future, Stream, stream::iter_ok};
use tokio_zmq::{prelude::*, async_types::MultipartStream, Error, Multipart, Pub, Socket};

fn main() {
    let context = Arc::new(zmq::Context::new());
    let zpub = Pub::builder(context)
        .connect("tcp://localhost:5570")
        .build()
        .unwrap();

    let fut = iter_ok(0..5)
        .and_then(|i| {
            let msg = zmq::Message::from_slice(format!("i: {}", i).as_bytes())?;
            Ok(msg.into()) as Result<Multipart, Error>
        })
        .forward(zpub.sink(25));

    // tokio::run(fut.map(|_| ()).or_else(|e| {
    //     println!("Error: {}", e);
    //     Ok(())
    // }));
}

Implementors§