6
zmq_proxy - start built-in 0MQ proxy
11
*int zmq_proxy (const void '*frontend', const void '*backend', const void '*capture');*
16
The _zmq_proxy()_ function starts the built-in 0MQ proxy in the current
19
The proxy connects a frontend socket to a backend socket. Conceptually, data
20
flows from frontend to backend. Depending on the socket types, replies may flow
21
in the opposite direction. The direction is conceptual only; the proxy is fully
22
symmetric and there is no technical difference between frontend and backend.
24
Before calling _zmq_proxy()_ you must set any socket options, and connect or
25
bind both frontend and backend sockets. The two conventional proxy models are:
27
_zmq_proxy()_ runs in the current thread and returns only if/when the current
30
If the capture socket is not NULL, the proxy shall send all messages, received
31
on both frontend and backend, to the capture socket. The capture socket should
32
be a 'ZMQ_PUB', 'ZMQ_DEALER', 'ZMQ_PUSH', or 'ZMQ_PAIR' socket.
34
Refer to linkzmq:zmq_socket[3] for a description of the available socket types.
42
When the frontend is a ZMQ_ROUTER socket, and the backend is a ZMQ_DEALER
43
socket, the proxy shall act as a shared queue that collects requests from a
44
set of clients, and distributes these fairly among a set of services.
45
Requests shall be fair-queued from frontend connections and distributed evenly
46
across backend connections. Replies shall automatically return to the client
47
that made the original request.
52
When the frontend is a ZMQ_XSUB socket, and the backend is a ZMQ_XPUB socket,
53
the proxy shall act as a message forwarder that collects messages from a set
54
of publishers and forwards these to a set of subscribers. This may be used to
55
bridge networks transports, e.g. read on tcp:// and forward on pgm://.
60
When the frontend is a ZMQ_PULL socket, and the backend is a ZMQ_PUSH socket,
61
the proxy shall collect tasks from a set of clients and forwards these to a set
62
of workers using the pipeline pattern.
66
The _zmq_proxy()_ function always returns `-1` and 'errno' set to *ETERM* (the
67
0MQ 'context' associated with either of the specified sockets was terminated).
72
.Creating a shared queue proxy
74
// Create frontend and backend sockets
75
void *frontend = zmq_socket (context, ZMQ_ROUTER);
77
void *backend = zmq_socket (context, ZMQ_DEALER);
79
// Bind both sockets to TCP ports
80
assert (zmq_bind (frontend, "tcp://*:5555") == 0);
81
assert (zmq_bind (backend, "tcp://*:5556") == 0);
82
// Start the queue proxy, which runs until ETERM
83
zmq_proxy (frontend, backend, NULL);
90
linkzmq:zmq_connect[3]
97
This 0MQ manual page was written by Pieter Hintjens <ph@imatix.com>