# rustzmq2
A native async Rust implementation of [ZeroMQ](https://zeromq.org/).
[](https://crates.io/crates/rustzmq2)
[](https://docs.rs/rustzmq2)
[](https://github.com/PoHsuanLai/rustzmq2/actions/workflows/main-ci.yml)
[](https://github.com/PoHsuanLai/rustzmq2/actions/workflows/bench.yml)
[](#license)
Send and receive messages across processes, machines, and languages using ZeroMQ — in pure async Rust, with no libzmq or libsodium dependency. Runs on tokio or smol; supports the full ZMTP security stack (PLAIN, CURVE, ZAP). Performance is on par with libzmq, with a meaningful edge on high-fanout PUB/XPUB workloads — see the [live head-to-head comparison](https://pohsuanlai.github.io/rustzmq2/comparison.html) (or [docs/BENCHMARKS.md](docs/BENCHMARKS.md) for methodology).
## Quick start
```toml
[dependencies]
rustzmq2 = "0.1"
tokio = { version = "1", features = ["full"] }
```
```rust
// server
use rustzmq2::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rep = rustzmq2::RepSocket::builder()
.receive_timeout(std::time::Duration::from_secs(30))
.build();
rep.bind("tcp://127.0.0.1:5555").await?;
loop {
let msg: String = rep.recv().await?.try_into()?;
rep.send(format!("{msg} reply").into()).await?;
}
}
```
```rust
// client
use rustzmq2::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut req = rustzmq2::ReqSocket::builder()
.connect_timeout(std::time::Duration::from_secs(5))
.build();
req.connect("tcp://127.0.0.1:5555").await?;
req.send("hello".into()).await?;
let reply: String = req.recv().await?.try_into()?;
println!("{reply}");
Ok(())
}
```
See [examples/](examples/) for pub/sub, security (PLAIN, CURVE, ZAP), and more.
## Platforms
| Linux (glibc, musl) | `ubuntu-latest` tests (x86_64); cross-compile checks for `aarch64-musl`, `riscv64-musl` | `tokio` and `smol` runtimes; TCP + IPC + inproc |
| macOS | `macos-latest` tests | `tokio` and `smol` runtimes; TCP + IPC + inproc |
| Windows | `windows-latest` tests | `tokio` runtime only; TCP + inproc (IPC requires Unix) |
| FreeBSD / NetBSD / illumos | cross-compile check only | no hardware test — `smol` build verified |
## Useful links
- [ZeroMQ project](https://zeromq.org/) — the messaging library this implements
- [ZeroMQ guide](https://zguide.zeromq.org/) — comprehensive patterns and concepts guide
- [ZMTP 3.1 spec (RFC 23)](https://rfc.zeromq.org/spec/23/) — wire protocol this crate implements
- [ZMTP PLAIN (RFC 24)](https://rfc.zeromq.org/spec/24/) — username/password mechanism
- [ZMTP CURVE (RFC 25)](https://rfc.zeromq.org/spec/25/) — elliptic-curve encryption mechanism
- [ZAP (RFC 27)](https://rfc.zeromq.org/spec/27/) — authentication protocol
- [Request/Reply (RFC 28)](https://rfc.zeromq.org/spec/28/) — REQ/REP/DEALER/ROUTER semantics
- [Publish/Subscribe (RFC 29)](https://rfc.zeromq.org/spec/29/) — PUB/SUB/XPUB semantics
## MSRV
Rust 1.85 or later.
## Attribution
rustzmq2 is a fork of [zeromq/zmq.rs](https://github.com/zeromq/zmq.rs). See [CREDITS.md](CREDITS.md).
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0))
- MIT license ([LICENSE-MIT](LICENSE-MIT) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT))
at your option.
The upstream [zeromq/zmq.rs](https://github.com/zeromq/zmq.rs) codebase is
MIT-only; its original contributors (see [CREDITS.md](CREDITS.md)) retain MIT
terms for their work. Contributions to this fork are dual-licensed under both
MIT and Apache-2.0 unless explicitly stated otherwise.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.