ZeroMQ: Distributed Messaging
This library provides bindings to the
ZeroMQ (or “0MQ”, or
“ZMQ”) distributed messaging library.
This package is distributed under the
General Public License (LGPL). As a client of this library you must
also comply with the libzmq license.
1 ZeroMQ Examples
This section contains examples of using this library adapted from the
1.1 Hello World in ZeroMQ
This example is adapted from
Ask and Ye Shall
Receive, which illustrates REP-REQ communication.
Here is the “hello world” server:
The first two lines of the server could also be combined into one, as follows:
Here is the “hello world” client:
1.2 Weather Reporting in ZeroMQ
This example is adapted from
Getting the Message Out,
which illustrates PUB-SUB communication.
Here’s the weather update server:
Here is the weather client:
2 ZeroMQ Functions
Returns #t if v is a ZeroMQ socket, #f otherwise.
Creates a new ZeroMQ socket of the given socket type and
initializes it with identity, subscriptions,
bind-endpoints, and connect-endpoints (in that order).
See the zmq_socket documentation for brief
descriptions of the different types of sockets, and see the
0MQ Guide for more detailed explanations.
Unlike libzmq, zmq-socket creates sockets with a short
default “linger” period (ZMQ_LINGER), to avoid blocking the
Racket VM when the underlying context is shut down. The linger period
can be changed with zmq-set-option.
Close the socket. Further operations on the socket will raise an
error, except that zmq-close
may be called on an
Returns #t if the socket is closed, #f otherwise.
List the endpoints the socket is bound or connected to (when
mode is 'bind or 'connect, respectively).
Gets or sets a socket option; see the API documentation for
, respectively. An option’s
symbol is obtained from the name of the corresponding C constant by
removing the ZMQ_
prefix and converting it to
lower-case. For example, ZMQ_IPV6
. Not all
options are supported. See also zmq-list-options
Connect or bind the socket s to the given endpoint(s).
See the transport documentation pages (tcp,
udp) for more information about transports and
their endpoint notations.
If endpoint refers to a filesystem path or network address,
access is checked against (current-security-guard). This
library cannot parse and check all endpoint formats supported by
libzmq; if endpoint is not in a supported format, an
exception is raised with the message “invalid endpoint or unsupported
endpoint format.” Clients may skip the parsing and access control
check by using zmq-unsafe-connect or
Disconnect or unbind the socket s from the given endpoint(s).
Note that in some cases endpoint must be more specific than the
argument to zmq-bind or zmq-connect. For example, see
the section labeled “Unbinding wild-card address from a socket” in
Adds or removes topic from a SUB ('sub) socket’s
subscription list. A SUB socket starts out with no subscriptions, and
thus receives no messages.
A topic matches a message if topic is a prefix of
the message. The empty topic accepts all messages.
Sends a message on socket s. The message has as many frames
as msg-frame arguments, with at least one frame required.
Sends the message msg on socket s, where
msg consists of a non-empty list of frames.
Receives a one-frame message from the socket s and returns
the single frame as a byte string or character string, respectively.
If a multi-frame message is received from s, an error is
raised. (The message is still consumed.)
Receives a message from the socket s. The message is
represented as a list of byte strings, one for each frame.
3 ZeroMQ Unsafe Functions
The functions provided by this module are unsafe.
, but do not attempt to
parse the endpoint
arguments and perform security guard
These functions are unsafe, not in the sense that misuse is likely to
cause memory corruption, but in the sense that they do not respect the
security guard mechanism.