Expand description
TMQ - Rust ZeroMQ bindings for Tokio
This crate bridges Tokio and ZeroMQ to allow for ZeroMQ in the async world.
Currently Implemented Sockets
- Request/Reply
- Publish/Subscribe
- Dealer/Router
- Push/Pull
Usage
Usage is made to be simple, but opinionated. See the examples/
Directory for some examples.
Publish Example
To publish messages to all connected subscribers, you can use the publish
function:
use tmq::{publish, Context, Result};
use futures::SinkExt;
use log::info;
use std::env;
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<()> {
let mut socket = publish(&Context::new()).bind("tcp://127.0.0.1:7899")?;
let mut i = 0;
loop {
i += 1;
socket
.send(vec!["topic", &format!("Broadcast #{}", i)])
.await?;
sleep(Duration::from_secs(1)).await;
}
}
Modules
- Dealer Sockets
- Pair Sockets
- Publish Sockets
- Pull Sockets
- Push Sockets
- Request/Reply Sockets
- Router Sockets
- Subscribe Sockets
Structs
- Handle for a 0MQ context, used to create sockets.
- Holds a 0MQ message.
- ZMQ multipart which holds individual messages.
Enums
- Internal re-exports Error that can occur during an async ZMQ operation.
Traits
- Trait for various ZMQ socket wrappers.
- Trait which defines configuration functions for ZMQ sockets.
Functions
- Create a builder for a DEALER socket.
- Create a builder for a PAIR socket.
- Create a builder for a PUB socket.
- Create a builder for a PULL socket.
- Create a builder for a PUSH socket.
- Create a builder for a REP socket
- Create a builder for a REQ socket
- Create a builder for a ROUTER socket.
- Create a builder for a SUB socket.
Type Definitions
- Shortcut for
Result<T, tmq::TmqError>
.