You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1.5 KiB

tokio-zeromq

Integrates zmq with tokio without adding much extra. Sometimes, less is more.

Usage

In your Cargo.toml, include tokio-zeromq as a dependency.

[dependencies.tokio-zeromq]
version = "0.3"
git = "https://git.fldcr.com/jafc/tokio-zeromq"
branch = "release"

Then, use tokio-zeromq::Socket type rather than zmq::Socket. The former derefs to the latter and adds two new async methods: send and recv_msg, to be used in place of zmq::Socket::send and zmq::Socket::recv_msg.

let ctx = zmq::Context::new();
let skt = tokio_zeromq::Socket::new(&ctx, zmq::SocketType::REQ).unwrap();
skt.connect("ipc://tmp/zmq.skt").unwrap();

skt.send("hello there").await.unwrap();
let resp = skt.recv_msg().await.unwrap();

skt.send_part("first frame of a multipart msg").await.unwrap();
skt.send("second (and final) frame of a multipart msg").await.unwrap();
let resp = skt.recv_msg().await.unwrap();

Alternatives

  • tmq: Up to date and works well, but it's more than a simple wrapper of zmq::Socket, and it requires the authors to add support for each socket type.
  • tokio-zmq: Last updated in June 2019; only has support for tokio 0.1 and earlier.
  • ... there are about 30 others. In order to avoid crowding crates.io with ZMQ packages, I've decided to just publish it via Git.