Expand description
§Thread-Safe ZeroMQ
A thread-safe wrapper around ZeroMQ sockets providing safe concurrent access through crossbeam channels, with optional async support via Tokio.
§The Problem
ZeroMQ sockets are explicitly NOT thread-safe. The ZMQ guide states: “Do not use or close sockets except in the thread that created them.” This is a fundamental design choice in libzmq for performance reasons.
However, real-world applications often need to send/receive from multiple threads. This library solves that by isolating all socket operations to dedicated background threads and exposing thread-safe channels to user code.
§Architecture
The key insight is that while we can’t share ZMQ sockets across threads, we CAN share channels. So we:
- Dedicate a thread to own and operate the ZMQ socket
- Use crossbeam channels to communicate between user threads and that socket thread
- Use internal ZMQ PAIR sockets to signal the socket thread (because zmq_poll can’t wait on channels, only sockets)
This gives us O(1) message passing with minimal synchronization overhead.
Structs§
- Async
Channel Pair - Async
Channel Pair Builder - Channel
Pair - Thread-safe wrapper around a ZeroMQ socket.
- Channel
Pair Builder - Builder for ChannelPair with fluent configuration API.
- Receiver
- Cloneable handle for receiving messages.
- Sender
- Cloneable handle for sending messages.
Enums§
- Async
Channel Capacity - Channel
Capacity - Channel capacity configuration.
- Channel
Pair Error
Type Aliases§
- ZmqMessage
- A multipart ZeroMQ message represented as a vector of byte frames.