omq-backend-rust
Rust-backed engine for OMQ. Same socket API, but networking runs on a Tokio runtime inside a native extension compiled via rb_sys.
Install
Requires a Rust toolchain (stable) at gem install time.
# Gemfile
gem "omq-backend-rust"
gem install omq-backend-rust
Usage
require "omq"
require "omq/backend/rust"
Async do
push = OMQ::PUSH.new(backend: :rust)
pull = OMQ::PULL.new(backend: :rust)
port = pull.bind("tcp://127.0.0.1:0").port
push.connect("tcp://127.0.0.1:#{port}")
push.peer_connected.wait
push << "hello from Rust"
p pull.receive # => ["hello from Rust"]
ensure
push&.close
pull&.close
end
The :rust backend is fully interoperable with the default :ruby backend.
Mix backends freely within the same process.
Supported socket types
All standard and draft ZMTP socket types: REQ/REP, PUB/SUB, PUSH/PULL, DEALER/ROUTER, XPUB/XSUB, PAIR, CLIENT/SERVER, RADIO/DISH, SCATTER/GATHER, CHANNEL.
Security mechanisms
- NULL (default)
- CURVE (CurveZMQ, via Nuckle)
Compressed transports
The Rust backend supports lz4+tcp:// and zstd+tcp://. Compression
configuration uses the same bind/connect kwargs as the Ruby transports:
level: for zstd compression level (-8..4), dict: for a static
send-side dictionary, and auto_dict: true for automatic dictionary
training.
Automatic dictionary training is off by default.
OMQ.rs stores compression configuration per socket, so pass these kwargs on
the first bind or connect for a Rust-backed socket.
Development
OMQ_DEV=1 bundle install
OMQ_DEV=1 bundle exec rake