This Zig library provides a ZeroMQ client.
It is implemented as a wrapper of the "High-level C Binding for ZeroMQ" (CZMQ).
IMPORTANT: The library is currently still work in progress!!
Since this library is basically a 1:1 wrapper of CZMQ, please refer to the CZMQ documentation to get a better understanding on how the library works. Please feel free to also have a look at the various unit tests in this library (esp. ZSocket).
Running the server (also see full example):
const zzmq = @import("zzmq");
var socket = try zzmq.ZSocket.init(allocator, zzmq.ZSocketType.Pair);
defer socket.deinit();
const port = try socket.bind("tcp://127.0.0.1:!");
// send a message
var frame = try zzmq.ZFrame.init(data);
defer frame.deinit();
try socket.send(&frame, .{});
Running the client (also see full example):
const zzmq = @import("zzmq");
var socket = try zzmq.ZSocket.init(allocator, zzmq.ZSocketType.Pair);
defer socket.deinit();
const endpoint = try std.fmt.allocPrint(allocator, "tcp://127.0.0.1:{}", .{port});
defer allocator.free(endpoint);
try socket.connect(endpoint);
// receive a message
var frame = try socket.receive();
defer frame.deinit();
const data = try frame.data();
Determine the specific release tag of the library to use in the project.
Add to the build.zig.zon
file, e.g. for Zig 0.11:
.{
.dependencies = .{
.zzmq = .{
.url = "https://github.com/nine-lives-later/zzmq/archive/refs/tags/v0.1.0-zig0.11.tar.gz",
.hash = "122080e22e9823dc0a4567c71553c4884978a33877c9b3d46f4594ca5f299d534f9b",
},
},
}
Note: Should the hash be wrong, remove the .hash
field and the compiler error will show the correct value. Starting with Zig 0.12 you can also use zig fetch zzmq <url>
.
It is also required to add it to the build.zig
file:
const zzmq = b.dependency("zzmq", .{
.target = target,
.optimize = optimize,
});
// Note: starting with zig 0.12 the function will be
// `exe.root_module.addImport` instead of `exe.addModule`
exe.addModule("zzmq", zzmq.module("zzmq"));
exe.linkSystemLibrary("czmq");
exe.linkLibC();
Installing CZMQ development library version 4.0 or higher is also required:
# Building on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq-dev
# Running on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libczmq
See the unit test Dockerfile on how to install it into an Alpine Docker image.
There are branches for the supported Zig versions:
Branch | Zig Version | Status | Comment |
---|---|---|---|
main |
Zig v0.11.x | The latest unreleased version for Zig 0.11. |
Please use a specific release tag for including the library into your project.
The library can be tested locally by running: zig build test
.
Implementation done by Felix Kollmann.
Based on the work of CZMQ, inspired by goczmq.
Published under the Mozilla Public License 2.0.
- Static linking is allowed.
- Safe for use in close-source applications.
- You do not need a commercial license.
Feel free to also see the ZeroMQ licensing terms.