Trait tokio_zmq::prelude::SinkSocket [−][src]
pub trait SinkSocket: AsSocket { fn send(self, multipart: Multipart) -> MultipartRequest<Self> { ... } fn sink(self) -> MultipartSink { ... } }
This trait provides the basic Sink support for ZeroMQ Sockets. It depends on AsSocket
and
provides the send
and sink
methods.
Provided Methods
fn send(self, multipart: Multipart) -> MultipartRequest<Self>
Send a single multipart message to the socket.
Example, using a Pub wrapper type
#![feature(try_from)] extern crate zmq; extern crate futures; extern crate tokio; extern crate tokio_zmq; use std::{convert::TryInto, sync::Arc}; use futures::Future; use tokio_zmq::{prelude::*, async::MultipartStream, Error, Pub, Socket}; fn main() { let context = Arc::new(zmq::Context::new()); let zpub: Pub = Socket::builder(context) .connect("tcp://localhost:5569") .try_into() .unwrap(); let msg = zmq::Message::from_slice(b"Hello").unwrap(); let fut = zpub.send(msg.into()); // tokio::runtime::run2(fut.map(|_| ()).or_else(|e| { // println!("Error: {}", e); // Ok(()) // })); }
fn sink(self) -> MultipartSink
Send a stream of multipart messages to the socket.
Example, using a Pub wrapper type
#![feature(try_from)] extern crate zmq; extern crate futures; extern crate tokio; extern crate tokio_zmq; use std::{convert::TryInto, sync::Arc}; use futures::{Future, Stream, stream::iter_ok}; use tokio_zmq::{prelude::*, async::MultipartStream, Error, Multipart, Pub, Socket}; fn main() { let context = Arc::new(zmq::Context::new()); let zpub: Pub = Socket::builder(context) .connect("tcp://localhost:5570") .try_into() .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()); // tokio::runtime::run2(fut.map(|_| ()).or_else(|e| { // println!("Error: {}", e); // Ok(()) // })); }