1ZMQ_PROXY(3) 0MQ Manual ZMQ_PROXY(3)
2
3
4
6 zmq_proxy - start built-in 0MQ proxy
7
9 int zmq_proxy (void *frontend, void *backend, void *capture);
10
12 The zmq_proxy() function starts the built-in 0MQ proxy in the current
13 application thread.
14
15 The proxy connects a frontend socket to a backend socket. Conceptually,
16 data flows from frontend to backend. Depending on the socket types,
17 replies may flow in the opposite direction. The direction is conceptual
18 only; the proxy is fully symmetric and there is no technical difference
19 between frontend and backend.
20
21 Before calling zmq_proxy() you must set any socket options, and connect
22 or bind both frontend and backend sockets. The two conventional proxy
23 models are:
24
25 zmq_proxy() runs in the current thread and returns only if/when the
26 current context is closed.
27
28 If the capture socket is not NULL, the proxy shall send all messages,
29 received on both frontend and backend, to the capture socket. The
30 capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or ZMQ_PAIR
31 socket.
32
33 Refer to zmq_socket(3) for a description of the available socket types.
34
36 Shared Queue
37 When the frontend is a ZMQ_ROUTER socket, and the backend is a
38 ZMQ_DEALER socket, the proxy shall act as a shared queue that collects
39 requests from a set of clients, and distributes these fairly among a
40 set of services. Requests shall be fair-queued from frontend
41 connections and distributed evenly across backend connections. Replies
42 shall automatically return to the client that made the original
43 request.
44
45 Forwarder
46 When the frontend is a ZMQ_XSUB socket, and the backend is a ZMQ_XPUB
47 socket, the proxy shall act as a message forwarder that collects
48 messages from a set of publishers and forwards these to a set of
49 subscribers. This may be used to bridge networks transports, e.g. read
50 on tcp:// and forward on pgm://.
51
52 Streamer
53 When the frontend is a ZMQ_PULL socket, and the backend is a ZMQ_PUSH
54 socket, the proxy shall collect tasks from a set of clients and
55 forwards these to a set of workers using the pipeline pattern.
56
58 The zmq_proxy() function always returns -1 and errno set to ETERM or
59 EINTR (the 0MQ context associated with either of the specified sockets
60 was terminated) or EFAULT (the provided frontend or backend was
61 invalid).
62
64 Creating a shared queue proxy.
65
66 // Create frontend and backend sockets
67 void *frontend = zmq_socket (context, ZMQ_ROUTER);
68 assert (frontend);
69 void *backend = zmq_socket (context, ZMQ_DEALER);
70 assert (backend);
71 // Bind both sockets to TCP ports
72 assert (zmq_bind (frontend, "tcp://*:5555") == 0);
73 assert (zmq_bind (backend, "tcp://*:5556") == 0);
74 // Start the queue proxy, which runs until ETERM
75 zmq_proxy (frontend, backend, NULL);
76
77
79 zmq_bind(3) zmq_connect(3) zmq_socket(3) zmq(7)
80
82 This page was written by the 0MQ community. To make a change please
83 read the 0MQ Contribution Policy at
84 http://www.zeromq.org/docs:contributing.
85
86
87
880MQ 4.3.4 07/23/2022 ZMQ_PROXY(3)