ruststream-zeromq connects a RustStream service to a ZeroMQ topology over the pure-Rust
zeromq implementation, on TCP and IPC. There is no server in
the middle, so a Rust service joins sockets a Python worker or a C++ daemon already speaks.
Handlers, routing, codecs and middleware come from the framework; this crate is the transport.
Features
- Three socket patterns:
ZmqQueue(PUSH/PULL, competing consumers),ZmqFanout(PUB/SUB, prefix filtering) andZmqRpc(DEALER/ROUTER, request and reply). - An explicit role: an endpoint either binds or connects, which is a deployment decision.
- A stable wire contract that a foreign peer composes by hand.
- Batches assembled on the client for the one-way patterns.
- Retry caps and dead letters applied by the framework.
- AsyncAPI with the transport, role and socket pair, behind the
asyncapifeature. - Tests without sockets: the service's own app runs with this crate's brokers in process.
Delivery is at most once, with no durability: acknowledgement reports AckError::Unsupported. A
subscriber that connects late misses what was sent before it arrived, and there is no encryption
layer.
The wire contract
frame 0: name UTF-8; also the subscription prefix for the fan-out pattern
frame 1: headers UTF-8 "name: value" lines separated by \n; may be empty
frame 2: payload encoded by the framework's codec
A Python peer sends socket.send_multipart([b"orders", b"content-type: application/json", payload]).
A two-frame message reads as one without headers.
Install
[]
= { = "0.7", = ["macros", "json"] }
= "0.7"
= { = "1", = ["derive"] }
[]
= { = "0.7", = ["testing"] }
Write a service
use *;
use ;
async
#[ruststream::app] generates main, so the binary understands run and asyncapi gen. Each
pattern has its own prelude (queue, fanout, rpc), so switching pattern changes the import.
Test it
TestApp runs the service's own app with this crate's brokers in process, with no sockets;
TestApp::start_live(app()) runs the same body over loopback sockets. Enable the testing
feature in [dev-dependencies].
use TestApp;
use Connect;
let tb = start.await?;
// A foreign peer's push; the injection returns once the handler has settled.
tb.
.message
.to
.publish
.await?;
tb.
.
.assert_called_once
.with;
Documentation
- This crate: https://docs.rs/ruststream-zeromq
- The framework: https://powersemmi.github.io/ruststream/latest
Minimum supported Rust version
The MSRV is 1.95, edition 2024.
Contributing
See CONTRIBUTING.md.
License
Licensed under the Apache-2.0 license.