QZeroMQ is a Qt library written in C++ for ØMQ, a widely used asynchronous messaging library. QZeroMQ provides an elegant socket API and seamlessly integrates with Qt's native event loop.
In short, QZeroMQ solves the problem of integrating ØMQ's sockets into Qt's native event loop. Solving this problem particularly challenging since ØMQ's socket gives only edge triggered notifications instead of level triggered notifications.
This is nicely explained in the articles ZeroMQ - Edge Triggered Notification and Embedding ZeroMQ In The Libev Event Loop.
QZeroMQ integrates with Qt's event loop via aboutToBlock()
and awake()
signals of QAbstractEventDispatcher.
The socket API of QZeroMQ can be used as follows.
// Global header file
#include <qzmq.hpp>
// Connecting to an end-point
QZmqSocket *client = QZmqSocket::create((ZMQ_PAIR);
client->connect("inproc://test");
// Binding to an end-point
QZmqSocket *server = QZmqSocket::create(ZMQ_PAIR);
server->bind("inproc://test");
// Connecting signals
connect(client, &QZmqSocket::onMessage, this, &MyClass::onClientMessage);
connect(server, &QZmqSocket::onMessage, this, &MyClass::onServerMessage);
// Sending messages
QZmqMessage *msg = QZmqMessage::create();
client->send(msg);
// Closing sockets
delete client;
delete server;
For more details, refer to the examples in the perf directory.
-
Like ØMQ sockets,
QZmqSockets
are NOT thread safe. No locks are used.QZmqSockets
cannot be moved between threads since eachQZmqSocket
is associated with the event loop of the thread in which the socket is created. In other words, create/destroyQZmqSockets
in the thread that use them. -
ØMQ's API can be used together with QZeroMQ's API with care.
Use
QZmqSocket::zmqSocket()
to access the underlying raw ØMQ socket. Therefore, QZeroMQ does not necessarily provide one-to-one mapped functions for all of the ØMQ's API functions.
QZeroMQ's build system is based on Cmake.
You can build QZeroMQ as follows with make.
# Create a directory for build artifacts
mkdir build
cd build
# Use Cmake to generate build tool (make) files
cmake .. -DCMAKE_PREFIX_PATH="<QT installation directory>;<ZeroMQ installation directory>" -DWITH_PERF_TOOL=ON
# Build using make
make
To be written
To be written
Coming soon..
QZeroMQ is licensed under the Apache License, Version 2.0.