⚠️ I wouldn't recommand using ZeroMQ or any ZeroMq bindings library (includinglibzmq-rs
), unless you absolutely have to. If you do, thenlibzmq-rs
might fit your use case since it basically makes ZeroMQ not a complete footgun. However, just because this library hides the unmaintainable mess that is ZeroMQ, doesn't mean the mess does not exist. See this comment for more context.
libzmq-rs
A strict subset of ØMQ with an ergonomic API.
[dependencies]
libzmq = "0.2"
use libzmq::{prelude::*, *};
use std::convert::TryInto;
// Use a system assigned port.
let addr: TcpAddr = "127.0.0.1:*".try_into()?;
let server = ServerBuilder::new()
.bind(addr)
.build()?;
// Retrieve the addr that was assigned.
let bound = server.last_endpoint()?;
let client = ClientBuilder::new()
.connect(bound)
.build()?;
// Send a string request.
client.send("tell me something")?;
// Receive the client request.
let msg = server.recv_msg()?;
let id = msg.routing_id().unwrap();
// Reply to the client.
server.route("it takes 224 bits to store a i32 in java", id)?;
// We can reply as much as we want.
server.route("also don't talk to me", id)?;
// Retreive the first reply.
let mut msg = client.recv_msg()?;
// And the second.
client.recv(&mut msg)?;
This crate builds and generates bindings from source. This means that you
do not need to install libzmq
. However building from source requires:
- CMake 2.8.12+ (or 3.0.2+ on Darwin)
- A c++ compiler
- Conform to these
API guidelines
. - Provide an ergonomic API
- Prevent footguns (which are plentifull in
libzmq
) - Minimize the learning curve
- Don't sacrifice any performance
- Extensively document
To do so we will only use a subset of libzmq
. If you'd rather have a complete
port, check out rust-zmq
.
See the FAQ
.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in libzmq
by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.