omq 0.1.0
omq: ^0.1.0 copied to clipboard
Fast ZeroMQ-compatible messaging for Dart on the OMQ engine, through the omq-libzmq C ABI.
OMQ.dart #
Dart binding for OMQ, backed by the omq-libzmq C ABI. It is pure Dart:
@Native calls with no native shim. Async waits run on the native ready
callback, so a pending receive() holds no thread.
2-process loopback TCP comparison against dartzmq on its bundled libzmq.
Throughput covers 16 B to 32 KiB; REQ/REP p50 latency covers 16 B to 4 KiB.
See DEVELOPMENT.md for benchmark and regeneration
commands.
Install #
dart pub add omq
The build hook downloads the prebuilt libomq_zmq for the target from the
omq-libzmq release this version pins, and checks its SHA-256. Prebuilt
libraries cover x86_64 and arm64 Linux (glibc 2.28 or later), x86_64 and
arm64 macOS, and x86_64 Windows. dart build cli copies the library into
the bundle. Requires Dart 3.10 or later.
To use another build, set a user-define in the app's pubspec.yaml:
hooks:
user_defines:
omq:
library: /path/to/libomq_zmq.so # bundle this file
# system: true # or load it via the system loader
API #
import 'package:omq/omq.dart';
Future<void> main() async {
final context = Context();
final pull = context.socket(SocketType.pull);
final push = context.socket(SocketType.push);
push.connect(pull.bind('tcp://127.0.0.1:*'));
await push.send(Message.text('hello'));
print((await pull.receive()).text);
context.close();
}
- Sends and receives come in three forms:
trySend/tryReceivenever block,sendSync/receiveSyncblock the isolate, andsend/receivereturn aFuture. Areceive(timeout:)that times out takes no message. socket.messagesis a stream. Pausing it leaves messages queued, so the HWM applies backpressure.Messageholds one or more frames, aroutingIdfor SERVER and PEER, and agroupfor RADIO and DISH.SocketOptionsapplies options at creation;setInt,setBytes, and theSocketOptionconstants cover the rest.configurePlainServer,configurePlainClient,configureCurveServer, andconfigureCurveClientset up security;CurveKeyPair.generate()makes keys. PLAIN authenticates but does not encrypt.socket.monitor()reports connection events.Context.shareKeyandContext.fromShareKeylet isolates share one native context and itsinproc://endpoints.
Use a socket from the isolate that created it, and close the context before that isolate exits.
Development #
Architecture: doc/architecture.md.
Build and test instructions: DEVELOPMENT.md.