ZMQ_PROXY(3)
π ZMQ_PROXY(3) β the 0MQ manual, bestie edition π
okay so you found the page for zmq_proxy, and honestly? she's iconic. this is the built-in 0MQ proxy and she's about to become your whole personality. let's get into it π«Ά
β¨ SYNOPSIS β¨
int zmq_proxy (void *frontend, void *backend, void *capture);
πΈ DESCRIPTION πΈ
The zmq_proxy() function starts the built-in 0MQ proxy in the current application thread. no forking, no extra threads, no drama β she runs right where you called her. π
The proxy connects a frontend socket to a backend socket. Conceptually, data flows from frontend to backend. Depending on the socket types, replies may flow in the opposite direction. and here's the thing β that direction is conceptual only. the proxy is fully symmetric and there is literally no technical difference between frontend and backend. it's giving "labels are a social construct" energy fr fr. π¦
Before calling zmq_proxy() you must set any socket options, and connect or bind both frontend and backend sockets. do not skip this step bestie, she will not do it for you. The two conventional proxy models are:
zmq_proxy() runs in the current thread and returns only if/when the current context is closed. so like, she's committed. she stays until the context says goodbye. π
If the capture socket is not NULL, the proxy shall send all messages, received on both frontend and backend, to the capture socket. The capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH, or ZMQ_PAIR socket. (yes queen, capture everything, we love a receipts moment β¨)
Refer to zmq_socket(3) for a description of the available socket types.
π EXAMPLE USAGE π
Shared Queue π
When the frontend is a ZMQ_ROUTER socket, and the backend is a ZMQ_DEALER socket, the proxy shall act as a shared queue that collects requests from a set of clients, and distributes these fairly among a set of services. Requests shall be fair-queued from frontend connections and distributed evenly across backend connections. Replies shall automatically return to the client that made the original request. no lost mail, no confused senders, she's just that organized. π
Forwarder π
When the frontend is a ZMQ_XSUB socket, and the backend is a ZMQ_XPUB socket, the proxy shall act as a message forwarder that collects messages from a set of publishers and forwards these to a set of subscribers. This may be used to bridge networks transports, e.g. read on tcp:// and forward on pgm://. lowkey a glow-up for your transport layer.
Streamer π§
When the frontend is a ZMQ_PULL socket, and the backend is a ZMQ_PUSH socket, the proxy shall collect tasks from a set of clients and forwards these to a set of workers using the pipeline pattern. assembly line but make it cute. π
π RETURN VALUE π
The zmq_proxy() function always returns -1 and errno set to ETERM or EINTR (the 0MQ context associated with either of the specified sockets was terminated) or EFAULT (the provided frontend or backend was invalid).
not me returning-1forever π β yes bestie, she never returns success. that's just her vibe. if you're seeingEFAULTit means your frontend or backend was invalid, so go check your sockets. π
π₯ EXAMPLE π₯
Creating a shared queue proxy.
// Create frontend and backend sockets
void *frontend = zmq_socket (context, ZMQ_ROUTER);
assert (frontend);
void *backend = zmq_socket (context, ZMQ_DEALER);
assert (backend);
// Bind both sockets to TCP ports
assert (zmq_bind (frontend, "tcp://*:5555") == 0);
assert (zmq_bind (backend, "tcp://*:5556") == 0);
// Start the queue proxy, which runs until ETERM
zmq_proxy (frontend, backend, NULL);
π SEE ALSO π
π AUTHORS π
This page was written by the 0MQ community. To make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. (the community ate, periodt. π«Ά)
and that's the whole page, bestie! this gorgeous little manual is from 0MQ 4.3.5, dated 10/09/2023, and it lives under the 0MQ Manual umbrella. go start a proxy, you main character. βπ
π¦ where this page comes from
- epel 10: zeromq 4.3.5-18.el10_0 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms