Convert Figma logo to code with AI

zeromq logolibzmq

ZeroMQ core engine in C++, implements ZMTP/3.1

9,619
2,347
9,619
329

Top Related Projects

5,956

nanomsg library

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin

Open source RabbitMQ: core server and tier 1 (built-in) plugins

28,317

Mirror of Apache Kafka

14,104

Apache Pulsar - distributed pub-sub messaging system

Quick Overview

ZeroMQ (libzmq) is a high-performance asynchronous messaging library, aimed at use in distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, ZeroMQ can run without a dedicated message broker.

Pros

  • High performance and low latency
  • Supports various messaging patterns (pub-sub, request-reply, push-pull)
  • Language-agnostic with bindings for many programming languages
  • Scalable and suitable for both small and large-scale distributed systems

Cons

  • Steep learning curve for beginners
  • Documentation can be overwhelming due to the many concepts and patterns
  • Debugging can be challenging in complex setups
  • Some advanced features may require careful configuration

Code Examples

  1. Simple Request-Reply Pattern:
#include <zmq.hpp>
#include <string>
#include <iostream>

int main()
{
    zmq::context_t context(1);
    zmq::socket_t socket(context, zmq::socket_type::rep);
    socket.bind("tcp://*:5555");

    while (true) {
        zmq::message_t request;
        socket.recv(request, zmq::recv_flags::none);
        std::cout << "Received: " << request.to_string() << std::endl;

        std::string reply = "World";
        socket.send(zmq::buffer(reply), zmq::send_flags::none);
    }

    return 0;
}
  1. Publish-Subscribe Pattern:
#include <zmq.hpp>
#include <string>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
    zmq::context_t context(1);
    zmq::socket_t publisher(context, zmq::socket_type::pub);
    publisher.bind("tcp://*:5563");

    while (true) {
        std::string message = "Hello";
        publisher.send(zmq::buffer("A " + message), zmq::send_flags::none);
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    return 0;
}
  1. Push-Pull Pattern:
#include <zmq.hpp>
#include <string>
#include <iostream>

int main()
{
    zmq::context_t context(1);
    zmq::socket_t pusher(context, zmq::socket_type::push);
    pusher.connect("tcp://localhost:5557");

    for (int i = 0; i < 100; ++i) {
        std::string msg = "Task " + std::to_string(i);
        pusher.send(zmq::buffer(msg), zmq::send_flags::none);
    }

    return 0;
}

Getting Started

To get started with libzmq:

  1. Install libzmq:

    • On Ubuntu: sudo apt-get install libzmq3-dev
    • On macOS with Homebrew: brew install zeromq
  2. Include ZeroMQ in your C++ project:

    #include <zmq.hpp>
    
  3. Compile your program with ZeroMQ:

    g++ -o program program.cpp -lzmq
    
  4. Run your program:

    ./program
    

Remember to handle errors and clean up resources properly in your actual implementations.

Competitor Comparisons

5,956

nanomsg library

Pros of nanomsg

  • Simpler API and easier to use for beginners
  • Better support for scalability protocols like survey and bus
  • More consistent behavior across different transport protocols

Cons of nanomsg

  • Smaller community and ecosystem compared to libzmq
  • Less mature and fewer production deployments
  • Limited language bindings compared to ZeroMQ

Code Comparison

nanomsg:

nn_socket_t sock = nn_socket(AF_SP, NN_PUB);
nn_bind(sock, "tcp://*:5555");
nn_send(sock, "Hello", 5, 0);
nn_close(sock);

libzmq:

void *context = zmq_ctx_new();
void *socket = zmq_socket(context, ZMQ_PUB);
zmq_bind(socket, "tcp://*:5555");
zmq_send(socket, "Hello", 5, 0);
zmq_close(socket);
zmq_ctx_destroy(context);

Both libraries provide similar functionality, but nanomsg's API is slightly more straightforward. However, libzmq offers more flexibility and control over the messaging process, which can be beneficial for complex applications.

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin

Pros of Protoactor-go

  • Higher-level abstraction for actor-based concurrency
  • Built-in clustering and remoting capabilities
  • Designed specifically for Go, leveraging its concurrency features

Cons of Protoactor-go

  • More opinionated and less flexible than libzmq
  • Steeper learning curve for developers unfamiliar with the actor model
  • Potentially higher overhead for simple messaging scenarios

Code Comparison

Protoactor-go:

type MyActor struct{}

func (state *MyActor) Receive(context actor.Context) {
    switch msg := context.Message().(type) {
    case string:
        fmt.Println("Received:", msg)
    }
}

props := actor.PropsFromProducer(func() actor.Actor { return &MyActor{} })
pid := actor.Spawn(props)

libzmq:

void *context = zmq_ctx_new();
void *socket = zmq_socket(context, ZMQ_REP);
zmq_bind(socket, "tcp://*:5555");

zmq_msg_t request;
zmq_msg_init(&request);
zmq_msg_recv(&request, socket, 0);

Protoactor-go provides a higher-level abstraction for building distributed systems using the actor model, while libzmq offers low-level messaging primitives. Protoactor-go is more suited for complex, scalable applications, whereas libzmq provides greater flexibility and control over communication patterns.

Open source RabbitMQ: core server and tier 1 (built-in) plugins

Pros of RabbitMQ

  • Built-in message persistence and durability
  • Supports multiple messaging protocols (AMQP, MQTT, STOMP)
  • Provides a management UI for monitoring and administration

Cons of RabbitMQ

  • Higher resource consumption and overhead
  • More complex setup and configuration
  • Less flexibility in terms of topology and communication patterns

Code Comparison

RabbitMQ (Erlang):

basic_publish(Channel, <<"my_exchange">>, <<"routing_key">>, <<"Hello, World!">>),
{#'basic.deliver'{delivery_tag = Tag}, Content} = basic_consume(Channel, <<"my_queue">>),
basic_ack(Channel, Tag)

ZeroMQ (C++):

zmq::socket_t socket(context, ZMQ_REQ);
socket.connect("tcp://localhost:5555");
zmq::message_t request(5);
memcpy(request.data(), "Hello", 5);
socket.send(request);

Key Differences

  • RabbitMQ is a full-featured message broker, while ZeroMQ is a lightweight messaging library
  • RabbitMQ requires a central server, whereas ZeroMQ is brokerless and can operate in various topologies
  • RabbitMQ offers out-of-the-box features like persistence and routing, while ZeroMQ provides more low-level control and flexibility
  • RabbitMQ has a steeper learning curve but offers more built-in functionality, while ZeroMQ is simpler to start with but requires more custom implementation for advanced features
28,317

Mirror of Apache Kafka

Pros of Kafka

  • Provides built-in data persistence and fault tolerance
  • Supports high-throughput, distributed streaming at scale
  • Offers strong ordering guarantees and exactly-once semantics

Cons of Kafka

  • More complex setup and configuration compared to libzmq
  • Higher resource requirements and overhead
  • Less flexible for lightweight, peer-to-peer messaging patterns

Code Comparison

libzmq (C++):

zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);
socket.connect("tcp://localhost:5555");
zmq::message_t request(5);
memcpy(request.data(), "Hello", 5);
socket.send(request);

Kafka (Java):

Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("topic", "Hello"));

Both libzmq and Kafka are powerful messaging systems, but they serve different purposes. libzmq is lightweight and flexible, ideal for low-latency, peer-to-peer communication. Kafka, on the other hand, excels in distributed streaming scenarios with high throughput and data persistence requirements.

14,104

Apache Pulsar - distributed pub-sub messaging system

Pros of Pulsar

  • Offers a more comprehensive messaging system with built-in storage and multi-tenancy
  • Provides better scalability for large-scale distributed systems
  • Includes features like geo-replication and tiered storage out of the box

Cons of Pulsar

  • Higher complexity and steeper learning curve compared to libzmq
  • Requires more resources and infrastructure to set up and maintain
  • Less flexibility for low-level customization of messaging patterns

Code Comparison

Pulsar (Java):

PulsarClient client = PulsarClient.builder()
    .serviceUrl("pulsar://localhost:6650")
    .build();
Producer<byte[]> producer = client.newProducer()
    .topic("my-topic")
    .create();
producer.send("Hello, Pulsar!".getBytes());

libzmq (C++):

zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_PUB);
socket.bind("tcp://*:5555");
zmq::message_t message(11);
memcpy(message.data(), "Hello, ZMQ!", 11);
socket.send(message);

Both libraries provide messaging capabilities, but Pulsar offers a higher-level abstraction with additional features, while libzmq provides more low-level control and flexibility. Pulsar is better suited for large-scale distributed systems, while libzmq is ideal for lightweight, customizable messaging solutions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ZeroMQ

Build Status Build status Coverage Status Conan Center

Welcome

The ZeroMQ lightweight messaging kernel is a library which extends the standard socket interfaces with features traditionally provided by specialised messaging middleware products. ZeroMQ sockets provide an abstraction of asynchronous message queues, multiple messaging patterns, message filtering (subscriptions), seamless access to multiple transport protocols and more.

Supported platforms

Libzmq is mainly written in C++98 with some optional C++11-fragments. For configuration either autotools or CMake is employed. See below for some lists of platforms, where libzmq has been successfully compiled on.

Supported platforms with primary CI

OS and versionArchitectureCompiler and versionBuild systemRemarks
Android NDK r25arm, arm64, x86, x86_64llvm (see NDK)autotoolsDRAFT
Ubuntu 14.04.5 LTS (trusty)amd64clang 5.0.0autotoolsSTABLE, extras: GSSAPI, PGM, NORM, C++98 mode only
Ubuntu 14.04.5 LTS (trusty)amd64gcc 4.8.4autotoolsSTABLE, DRAFT, extras: GSSAPI, PGM, NORM, TIPC, IPV6, also POLLER=poll, POLLER=select, also valgrind and address sanitizer executions
Ubuntu 14.04.5 LTS (trusty)amd64gcc 4.8.4CMake 3.12.2STABLE
Windows Server 2012 R2x86Visual Studio 2008CMake 3.12.2DRAFT
Windows Server 2012 R2x86Visual Studio 2010 SP1CMake 3.12.2DRAFT
Windows Server 2012 R2x86Visual Studio 2012 Update 5CMake 3.12.2DRAFT
Windows Server 2012 R2x86, amd64Visual Studio 2013 Update 5CMake 3.12.2DRAFT, STABLE (x86 Release only), also POLLER=epoll
Windows Server 2012 R2x86Visual Studio 2015 Update 3CMake 3.12.2DRAFT
Windows Server 2016x86Visual Studio 2017 15.9.6CMake 3.13.3DRAFT
cygwin 3.0.0 on Windows Server 2012 R2amd64gcc 7.4.0CMake 3.6.2DRAFT
MSYS2 ? on Windows Server 2012 R2amd64gcc 6.4.0CMake ?DRAFT
Mac OS X 10.13amd64Xcode 9.4.1, Apple LLVM 9.1.0autotoolsSTABLE, DRAFT
Mac OS X 10.13amd64Xcode 9.4.1, Apple LLVM 9.1.0CMake 3.11.4DRAFT

Note: the platforms are regularly updated by the service providers, so this information might get out of date without any changes on the side of libzmq. For Appveyor, refer to https://www.appveyor.com/updates/ regarding platform updates. For travis-ci, refer to https://changelog.travis-ci.com/ regarding platform updates.

Supported platforms with secondary CI

OS and versionArchitectureCompiler and versionBuild systemRemarks
CentOS 6x86, amd64?autotools
CentOS 7amd64?autotools
Debian 8.0x86, amd64?autotools
Debian 9.0ARM64, x86, amd64?autotools
Fedora 28ARM64, ARM32, amd64?autotools
Fedora 29ARM64, ARM32, amd64?autotools
Fedora RawhideARM64, ARM32, amd64?autotools
RedHat Enterprise Linux 7amd64, ppc64?autotools
SuSE Linux Enterprise 12 SP4ARM64, amd64, ppc64, s390x?autotools
SuSE Linux Enterprise 15amd64?autotools
xUbuntu 12.04x86, amd64?autotools
xUbuntu 14.04x86, amd64?autotools
xUbuntu 16.04x86, amd64?autotools
xUbuntu 18.04x86, amd64?autotools
xUbuntu 18.10x86, amd64?autotools

Supported platforms with known active users

At the time of writing, no explicit reports have been available. Please report your experiences by opening a PR adding an entry or moving an entry from the section below.

Under "last report", please name either the SHA1 in case of an unreleased version, or the version number in case of a released version.

OS and versionArchitectureCompiler and versionBuild systemLast reportRemarks
Solaris 10x86, amd64, sparcGCC 8.1.0CMake2019/03/18
DragonFly BSDamd64gcc 8.3autotools2018/08/07 git-72854e63
IBM ippc64gcc 6.3autotools2019/10/02 git-25320a3
QNX 7.0x86_64gcc 5.4.0CMake4.3.2
Windows 10ARM64Visual Studio 2019CMake2021/11/15 git-2375ca8b
Windows 10ARM64clangCMake2021/11/15 git-2375ca8b

Supported platforms without known active users

Note: this list is incomplete and inaccurate and still needs some work.

OS and versionArchitectureCompiler and versionBuild systemRemarks
Any Linux distributionx86, amd64gcc ?+, clang ?+, icc ?+autotools, CMake
SunOS, Solarisx86, amd64SunProautotools, CMake
GNU/kFreeBSD??autotools, CMake
FreeBSD??autotools, CMake
NetBSD??autotools, CMake
OpenBSD??autotools, CMake
DragonFly BSDamd64gcc 8.3autotools, CMake
HP-UX??autotools, CMake
GNU/Hurd??autotools
VxWorks 6.8???
Windows CE???
Windows UWP???
OpenVMS???

Unsupported platforms

OS and versionArchitectureCompiler and versionRemarks
QNX 6.3?gcc 3.3.5see #3371, support was added by a user, but not contributed to upstream

For more details, see here.

For some platforms (Linux, Mac OS X), prebuilt binary packages are supplied by the ZeroMQ organization. For other platforms, you need to build your own binaries.

Installation of binary packages

Linux

For Linux users, pre-built binary packages are available for most distributions. Note that DRAFT APIs can change at any time without warning, pick a STABLE build to avoid having them enabled.

Latest releases

DEB

OBS release stable OBS release draft

RPM

OBS release stable OBS release draft

Bleeding edge packages

DEB

OBS release stable OBS release draft

RPM

OBS release stable OBS release draft

Example: Debian 9 latest release, no DRAFT apis

echo "deb http://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/ ./" >> /etc/apt/sources.list
wget https://download.opensuse.org/repositories/network:/messaging:/zeromq:/release-stable/Debian_9.0/Release.key -O- | sudo apt-key add
apt-get install libzmq3-dev

OSX

For OSX users, packages are available via brew.

brew install zeromq

Installation of package manager

vcpkg

vcpkg is a full platform package manager, you can easily install libzmq via vcpkg.

git clone https://github.com/microsoft/vcpkg.git
./bootstrap-vcpkg.bat # For powershell
./bootstrap-vcpkg.sh # For bash
./vcpkg install zeromq

Build from sources

To build from sources, see the INSTALL file included with the distribution.

Android

To build from source, see README file in the android build directory.

Resources

Extensive documentation is provided with the distribution. Refer to doc/zmq.html, or "man zmq" after you have installed libzmq on your system.

Website: http://www.zeromq.org/

Development mailing list: zeromq-dev@lists.zeromq.org Announcements mailing list: zeromq-announce@lists.zeromq.org

Git repository: http://github.com/zeromq/libzmq

ZeroMQ developers can also be found on the IRC channel #zeromq, on the Libera Chat network (irc.libera.chat).

License

The project license is specified in LICENSE.

libzmq is free software; you can redistribute it and/or modify it under the terms of the Mozilla Public License Version 2.0.

Contributing

This project uses C4(Collective Code Construction Contract) process for contributions.