Skip to main content

omq 0.1.1 copy "omq: ^0.1.1" to clipboard
omq: ^0.1.1 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.

OMQ.dart performance

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/tryReceive never block, sendSync/receiveSync block the isolate, and send/receive return a Future. A receive(timeout:) that times out takes no message.
  • socket.messages is a stream. Pausing it leaves messages queued, so the HWM applies backpressure.
  • Message holds one or more frames, a routingId for SERVER and PEER, and a group for RADIO and DISH.
  • SocketOptions applies options at creation; setInt, setBytes, and the SocketOption constants cover the rest.
  • configurePlainServer, configurePlainClient, configureCurveServer, and configureCurveClient set up security; CurveKeyPair.generate() makes keys. PLAIN authenticates but does not encrypt.
  • socket.monitor() reports connection events.
  • Context.shareKey and Context.fromShareKey let isolates share one native context and its inproc:// 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.

0
likes
150
points
24
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Fast ZeroMQ-compatible messaging for Dart on the OMQ engine, through the omq-libzmq C ABI.

Repository (GitHub)
View/report issues
Contributing

Topics

#zeromq #messaging #networking #ffi

License

ISC (license)

Dependencies

code_assets, crypto, ffi, hooks

More

Packages that depend on omq