Git Product home page Git Product logo

zzmq's Introduction

Zig Binding for ZeroMQ

This Zig library provides a ZeroMQ client.

It is implemented based on the C API of libzmq. The interface is highly inspired by CZMQ and goczmq.

It was originally based on the "High-level C Binding for ZeroMQ" (CZMQ), but later moved to using libzmq directly, to provide zero-copy message support.

Important

The library is currently still work in progress!!

Please feel free to open pull requests for features needed.

Unit Tests Examples

Using the Library

Minimal Example

This repository holds various example within the examples folder. 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 context = try zzmq.ZContext.init(allocator);
defer context.deinit();

var socket = try zzmq.ZSocket.init(zzmq.ZSocketType.Pair, &context);
defer socket.deinit();

try socket.bind("tcp://127.0.0.1:*");

std.log.info("Endpoint: {s}", .{try socket.endpoint()});

// send a message
var message = try zzmq.ZMessage.initUnmanaged(data, null);
defer message.deinit();

try socket.send(&message, .{});

Running the client (also see full example):

const zzmq = @import("zzmq");

var context = try zzmq.ZContext.init(allocator);
defer context.deinit();

var socket = try zzmq.ZSocket.init(zzmq.ZSocketType.Pair, &context);
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 message = try socket.receive(.{});
defer message.deinit();

const data = try message.data();

Adding to build process

Determine the specific release tag of the library to use in the project.

zig fetch --save=zzmq 'https://github.com/nine-lives-later/zzmq/archive/refs/tags/v0.2.2-zig0.12.tar.gz'

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("zmq");
exe.linkLibC();

Installing local dependencies

Installing libzmq development library version 4.1 or higher is also required:

# Building on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libzmq5-dev

# Running on Ubuntu, PoP_OS, ZorinOS, etc.
sudo apt install libzmq5

See the unit test Dockerfile on how to install it into an Alpine Docker image.

To retrieve the version of the libzmq library actually being used, call ZContext.version().

Contributing

Zig Version Branches

There are branches for the supported Zig versions:

Branch Zig Version Status Comment
main Zig v0.12.x Unit Tests The latest unreleased version for Zig 0.12.
zig-0.11 Zig v0.11.x Unit Tests The latest unreleased version for Zig 0.11.

Please use a specific release tag for including the library into your project.

Testing

The library can be tested locally by running: zig build test.

Contributors

License

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.

zzmq's People

Contributors

fkollmann avatar 7zifle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.