1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/* * This file is part of Tokio ZMQ. * * Copyright © 2017 Riley Trautman * * Tokio ZMQ is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Tokio ZMQ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Tokio ZMQ. If not, see <http://www.gnu.org/licenses/>. */ #![feature(conservative_impl_trait)] #![feature(try_from)] //! Tokio ZMQ, bringing ZeroMQ to the Tokio event loop //! //! This crate provides Streams, Sinks, and Futures for ZeroMQ Sockets, which deal in structures //! caled Multiparts. Currently, a Multipart is a simple wrapper around `VecDeque<zmq::Message>`, //! but in the future this will be represented as a wrapper around `VecDeque<S: zmq::Sendable>` //! with the zmq 0.9 release. //! //! # Creating a socket //! //! To get a new socket, you must invoke the Socket builder. The Socket Builder can output a //! 'raw' Socket, or any specific kind of socket, such as Rep, Req, etc. The result of the builder //! can be any compatable kind of socket, so specifiying a type is important. //! //! Once you have a socket, if it implements `StreamSocket`, you can use the socket's `.stream()`, if //! it implements `SinkSocket`, you can use the socket's `.sink()`, and if it implements //! `FutureSocket`, you can use the `send` and `recv` methods. //! //! Without further ado, creating and using a socket: //! //! ```rust //! #![feature(try_from)] //! //! extern crate zmq; //! extern crate futures_util; //! extern crate tokio; //! extern crate tokio_zmq; //! //! use std::convert::TryInto; //! use std::sync::Arc; //! //! use futures_util::{FutureExt, StreamExt}; //! use tokio_zmq::prelude::*; //! use tokio_zmq::{Socket, Pub, Sub, Error}; //! //! fn run() -> Result<(), Error> { //! // Create a new ZeroMQ Context. This context will be used to create all the sockets. //! let context = Arc::new(zmq::Context::new()); //! //! // Create our two sockets using the Socket builder pattern. //! // Note that the variable is named zpub, since pub is a keyword //! let zpub: Pub = Socket::builder(Arc::clone(&context)) //! .bind("tcp://*:5561") //! .try_into()?; //! //! let sub: Sub = Socket::builder(context) //! .bind("tcp://*:5562") //! .filter(b"") //! .try_into()?; //! //! // Create our simple server. This forwards messages from the Subscriber socket to the //! // Publisher socket, and prints them as they go by. //! let runner = sub.stream() //! .map(|multipart| { //! for msg in &multipart { //! if let Some(msg) = msg.as_str() { //! println!("Forwarding: {}", msg); //! } //! } //! multipart //! }) //! .forward(zpub.sink()); //! //! // To avoid an infinte doctest, the actual core.run is commented out. //! // tokio::runtime::run2(runner.map(|_| ()).or_else(|e| { //! // println!("Error: {}", e); //! // })?; //! # let _ = runner; //! # Ok(()) //! } //! //! # fn main() { //! # run().unwrap(); //! # } //! ``` extern crate futures_core; extern crate futures_sink; extern crate futures_util; #[macro_use] extern crate log; extern crate mio; extern crate tokio; extern crate tokio_file_unix; extern crate tokio_timer_futures2 as tokio_timer; #[macro_use] extern crate tokio_zmq_derive; extern crate zmq; mod error; mod message; pub mod async; pub mod socket; pub mod file; pub mod prelude; pub use self::error::Error; pub use self::message::Multipart; pub use self::socket::Socket; pub use self::socket::types::{Dealer, Pair, Pub, Pull, Push, Rep, Req, Router, Sub, Xpub, Xsub};