Documentation

  lang:   lib:

Get started

ZeroMQ (also spelled ØMQ, 0MQ or ZMQ) 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, a ZeroMQ system can run without a dedicated message broker.

ZeroMQ supports common messaging patterns (pub/sub, request/reply, client/server and others) over a variety of transports (TCP, in-process, inter-process, multicast, WebSocket and more), making inter-process messaging as simple as inter-thread messaging. This keeps your code clear, modular and extremely easy to scale.

ZeroMQ is developed by a large community of contributors. There are third-party bindings for many popular programming languages and native ports for C# and Java.

The Zero in ZeroMQ

The philosophy of ZeroMQ starts with the zero. The zero is for zero broker (ZeroMQ is brokerless), zero latency, zero cost (it’s free), and zero administration.

More generally, “zero” refers to the culture of minimalism that permeates the project. We add power by removing complexity rather than by exposing new functionality.

The Guide

The guide explains how to use ØMQ, covers basic, intermediate and advanced use with 60+ diagrams and 750 examples in 28 languages.

Also available as a book O’Reilly.

Libzmq - the low level library

Libzmq (https://github.com/zeromq/libzmq) is the low-level library behind most of the different language bindings. Libzmq expose C-API and implemented in C++. You will rarely use libzmq directly, however if you want to contribute to the project or learn the internals of zeromq, that is the place to start.

Pick your language

Pick your library

libzmq | C

ZeroMQ core engine in C++
engine
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

czmq | C

High-level binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

zmqpp | C++

High-level binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

cppzmq | C++

Header-only C++ binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

azmq | C++

Boost Asio style binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

czmqpp | C++

Minimal, simple wrapper for czmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

NetMQ | C#

ZeroMQ engine in C# for .Net
engine
tcp, inproc, pgm
PLAIN

clrzmq4 | C#

.Net binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

Chumak | Erlang

ZeroMQ engine in Erlang
engine
tcp
PLAIN, CURVE

ezmq | Erlang

ZeroMQ engine in Erlang
engine
tcp

erlang-czmq | Erlang

Erlang binding for czmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

FsNetMQ | F#

F# binding for NetMQ
binding
tcp, inproc, pgm
PLAIN

fszmq | F#

F# binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

zmq4 | Go

Go binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

goczmq | Go

Go binding for czmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

zeromq-haskell | Haskell

Haskell binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

JeroMQ | Java

ZeroMQ engine in pure Java
engine
tcp, inproc, ipc (JeroMQ only)
PLAIN, CURVE

JZMQ | Java

JNI binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

jczmq | Java

JNI binding for czmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

zeromqjs | Node.js

Node.js binding for czmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

perlzmq | Perl

Perl binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

Pyzmq | Python

Python binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

rbzmq | Ruby

Ruby binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

rust-zmq | Rust

Rust binding for libzmq
binding
tcp, udp, pgm, norm, ipc, inproc, gssapi
PLAIN, CURVE

First example

So let’s start with some code, the “Hello world” example (of course).

//  Hello World sever
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main (void)
{
    //  Socket to talk to clients
    void *context = zmq_ctx_new ();
    void *responder = zmq_socket (context, ZMQ_REP);
    int rc = zmq_bind (responder, "tcp://*:5555");
    assert (rc == 0);

    while (1) {
        char buffer [10];
        zmq_recv (responder, buffer, 10, 0);
        printf ("Received Hello\n");
        sleep (1);          //  Do some 'work'
        zmq_send (responder, "World", 5, 0);
    }
    return 0;
}
//  Hello World server
#include <czmq.h>

int main (void)
{
    //  Socket to talk to clients
    zsock_t *responder = zsock_new (ZMQ_REP);
    int rc = zsock_bind (responder, "tcp://*:5555");
    assert (rc == 0);

    while (1) {
        char *str = zstr_recv (responder);
        printf ("Received Hello\n");
        sleep (1);          //  Do some 'work'
        zstr_send (responder, "World");
        zstr_free (&str);
    }
    return 0;
}
Example hello_world_server is missing for zmqpp. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/zmqpp
cp archetypes/examples/hello_world_server.md
content/docs/examples/cpp/zmqpp/hello_world_server.md
Example hello_world_server is missing for cppzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/cppzmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/cpp/cppzmq/hello_world_server.md
Example hello_world_server is missing for azmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/azmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/cpp/azmq/hello_world_server.md
Example hello_world_server is missing for czmqpp. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/czmqpp
cp archetypes/examples/hello_world_server.md
content/docs/examples/cpp/czmqpp/hello_world_server.md
using System;
using System.Threading;
using NetMQ;
using NetMQ.Sockets;

static class Program
{
    public static void Main()
    {        
        using (var responder = new ResponseSocket())
        {
            responder.Bind("tcp://*:5555");

            while (true) 
            {
                string str = responder.ReceiveFrameString();
                Console.WriteLine("Received Hello");
                Thread.Sleep(1000);  //  Do some 'work'
                responder.SendFrame("World");
            }
        }
    }
}
Example hello_world_server is missing for clrzmq4. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/csharp/clrzmq4
cp archetypes/examples/hello_world_server.md
content/docs/examples/csharp/clrzmq4/hello_world_server.md
Example hello_world_server is missing for Chumak. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/chumak
cp archetypes/examples/hello_world_server.md
content/docs/examples/erlang/chumak/hello_world_server.md
Example hello_world_server is missing for ezmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/ezmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/erlang/ezmq/hello_world_server.md
Example hello_world_server is missing for erlang-czmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/erlang-czmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/erlang/erlang-czmq/hello_world_server.md
Example hello_world_server is missing for FsNetMQ. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/fsharp/fsnetmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/fsharp/fsnetmq/hello_world_server.md
Example hello_world_server is missing for fszmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/fsharp/fszmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/fsharp/fszmq/hello_world_server.md
Example hello_world_server is missing for zmq4. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/go/zmq4
cp archetypes/examples/hello_world_server.md
content/docs/examples/go/zmq4/hello_world_server.md
Example hello_world_server is missing for goczmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/go/goczmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/go/goczmq/hello_world_server.md
Example hello_world_server is missing for zeromq-haskell. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/haskell/zeromq-haskell
cp archetypes/examples/hello_world_server.md
content/docs/examples/haskell/zeromq-haskell/hello_world_server.md
//  Hello World server in Java
//  Binds REP socket to tcp://*:5555
//  Expects "Hello" from client, replies with "World"

import org.zeromq.SocketType;
import org.zeromq.ZMQ;
import org.zeromq.ZContext;

public class hwserver
{
  public static void main(String[] args) throws Exception
  {
    try (ZContext context = new ZContext()) {
      //  Socket to talk to clients
      ZMQ.Socket socket = context.createSocket(SocketType.REP);
      socket.bind("tcp://*:5555");

      while (!Thread.currentThread().isInterrupted()) {
        byte[] reply = socket.recv(0);
        System.out.println(
          "Received " + ": [" + new String(reply, ZMQ.CHARSET) + "]"
        );
        String response = "world";
        socket.send(response.getBytes(ZMQ.CHARSET), 0);
        Thread.sleep(1000); //  Do some 'work'
      }
    }
  }
}
Example hello_world_server is missing for JZMQ. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/java/jzmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/java/jzmq/hello_world_server.md
Example hello_world_server is missing for jczmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/java/jczmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/java/jczmq/hello_world_server.md
Example hello_world_server is missing for zeromqjs. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/nodejs/zeromqjs
cp archetypes/examples/hello_world_server.md
content/docs/examples/nodejs/zeromqjs/hello_world_server.md
Example hello_world_server is missing for perlzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/perl/perlzmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/perl/perlzmq/hello_world_server.md
Example hello_world_server is missing for Pyzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/python/pyzmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/python/pyzmq/hello_world_server.md
Example hello_world_server is missing for rbzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/ruby/rbzmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/ruby/rbzmq/hello_world_server.md
Example hello_world_server is missing for rust-zmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/rust/rust-zmq
cp archetypes/examples/hello_world_server.md
content/docs/examples/rust/rust-zmq/hello_world_server.md

The server creates a socket of type response (you will read more about request-response later), binds it to port 5555 and then waits for messages. You can also see that we have zero configuration, we are just sending strings.

//  Hello World client
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main (void)
{
    printf ("Connecting to hello world server…\n");
    void *context = zmq_ctx_new ();
    void *requester = zmq_socket (context, ZMQ_REQ);
    zmq_connect (requester, "tcp://localhost:5555");

    int request_nbr;
    for (request_nbr = 0; request_nbr != 10; request_nbr++) {
        char buffer [10];
        printf ("Sending Hello %d…\n", request_nbr);
        zmq_send (requester, "Hello", 5, 0);
        zmq_recv (requester, buffer, 10, 0);
        printf ("Received World %d\n", request_nbr);
    }
    zmq_close (requester);
    zmq_ctx_destroy (context);
    return 0;
}
//  Hello World client
#include <czmq.h>

int main (void)
{
    printf ("Connecting to hello world server…\n");
    zsock_t *requester = zsock_new (ZMQ_REQ);
    zsock_connect (requester, "tcp://localhost:5555");

    int request_nbr;
    for (request_nbr = 0; request_nbr != 10; request_nbr++) {
        printf ("Sending Hello %d…\n", request_nbr);
        zstr_send (requester, "Hello");
        char *str = zstr_recv (requester);
        printf ("Received World %d\n", request_nbr);
        zstr_free (&str);
    }
    zsock_destroy (&requester);
    return 0;
}
Example hello_world_client is missing for zmqpp. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/zmqpp
cp archetypes/examples/hello_world_client.md
content/docs/examples/cpp/zmqpp/hello_world_client.md
Example hello_world_client is missing for cppzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/cppzmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/cpp/cppzmq/hello_world_client.md
Example hello_world_client is missing for azmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/azmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/cpp/azmq/hello_world_client.md
Example hello_world_client is missing for czmqpp. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/cpp/czmqpp
cp archetypes/examples/hello_world_client.md
content/docs/examples/cpp/czmqpp/hello_world_client.md
using System;
using NetMQ;
using NetMQ.Sockets;

static class Program
{
    public static void Main()
    {
        Console.WriteLine("Connecting to hello world server…");
        using(var requester = new RequestSocket())
        {
            requester.Connect("tcp://localhost:5555");

            int requestNumber;
            for (requestNumber = 0; requestNumber != 10; requestNumber++)
            {
                Console.WriteLine("Sending Hello {0}...", requestNumber);
                requester.SendFrame("Hello");
                string str = requester.ReceiveFrameString();
                Console.WriteLine("Received World {0}", requestNumber);
            }
        }
    }    
}
Example hello_world_client is missing for clrzmq4. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/csharp/clrzmq4
cp archetypes/examples/hello_world_client.md
content/docs/examples/csharp/clrzmq4/hello_world_client.md
Example hello_world_client is missing for Chumak. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/chumak
cp archetypes/examples/hello_world_client.md
content/docs/examples/erlang/chumak/hello_world_client.md
Example hello_world_client is missing for ezmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/ezmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/erlang/ezmq/hello_world_client.md
Example hello_world_client is missing for erlang-czmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/erlang/erlang-czmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/erlang/erlang-czmq/hello_world_client.md
Example hello_world_client is missing for FsNetMQ. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/fsharp/fsnetmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/fsharp/fsnetmq/hello_world_client.md
Example hello_world_client is missing for fszmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/fsharp/fszmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/fsharp/fszmq/hello_world_client.md
Example hello_world_client is missing for zmq4. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/go/zmq4
cp archetypes/examples/hello_world_client.md
content/docs/examples/go/zmq4/hello_world_client.md
Example hello_world_client is missing for goczmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/go/goczmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/go/goczmq/hello_world_client.md
Example hello_world_client is missing for zeromq-haskell. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/haskell/zeromq-haskell
cp archetypes/examples/hello_world_client.md
content/docs/examples/haskell/zeromq-haskell/hello_world_client.md
//  Hello World client in Java
//  Connects REQ socket to tcp://localhost:5555
//  Sends "Hello" to server, expects "World" back

import org.zeromq.SocketType;
import org.zeromq.ZMQ;
import org.zeromq.ZContext;

public class hwclient
{
    public static void main(String[] args)
    {
        try (ZContext context = new ZContext()) {
            System.out.println("Connecting to hello world server");

      		//  Socket to talk to server
            ZMQ.Socket socket = context.createSocket(SocketType.REQ);
            socket.connect("tcp://localhost:5555");

            for (int requestNbr = 0; requestNbr != 10; requestNbr++) {
                String request = "Hello";
                System.out.println("Sending Hello " + requestNbr);
                socket.send(request.getBytes(ZMQ.CHARSET), 0);

                byte[] reply = socket.recv(0);
                System.out.println(
                    "Received " + new String(reply, ZMQ.CHARSET) + " " +
                    requestNbr
                );
            }
        }
    }
}
Example hello_world_client is missing for JZMQ. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/java/jzmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/java/jzmq/hello_world_client.md
Example hello_world_client is missing for jczmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/java/jczmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/java/jczmq/hello_world_client.md
Example hello_world_client is missing for zeromqjs. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/nodejs/zeromqjs
cp archetypes/examples/hello_world_client.md
content/docs/examples/nodejs/zeromqjs/hello_world_client.md
Example hello_world_client is missing for perlzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/perl/perlzmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/perl/perlzmq/hello_world_client.md
Example hello_world_client is missing for Pyzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/python/pyzmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/python/pyzmq/hello_world_client.md
Example hello_world_client is missing for rbzmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/ruby/rbzmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/ruby/rbzmq/hello_world_client.md
Example hello_world_client is missing for rust-zmq. Would you like to contribute it? Then follow the steps below:
git clone https://github.com/zeromq/zeromq.org
cd zeromq.org && mkdir -p content/docs/examples/rust/rust-zmq
cp archetypes/examples/hello_world_client.md
content/docs/examples/rust/rust-zmq/hello_world_client.md

The client creates a socket of type request, connects and starts sending messages.

Both the send and receive methods are blocking (by default). For the receive it is simple: if there are no messages the method will block. For sending it is more complicated and depends on the socket type. For request sockets, if the high watermark is reached or no peer is connected the method will block.