ZMQ_PROXY_STEERABLE(3)
โจ ZMQ_PROXY_STEERABLE(3) โจ
okay so bestie, this is a page from the 0MQ Manual and it's about the built-in 0MQ proxy that you can literally steer, like it's a little remote-controlled car except it's a message-forwarding machine ๐
๐ธ NAME ๐ธ
zmq_proxy_steerable โ the built-in 0MQ proxy with control flow ๐
๐ฆ SYNOPSIS ๐ฆ
int zmq_proxy_steerable (const void *frontend, const void *backend,
const void *capture, const void *control);
๐ DESCRIPTION ๐
So zmq_proxy_steerable() is basically zmq_proxy() but with a glow-up: it takes a fourth socket, the control socket. And here's the tea โ if that control socket is NULL, the two functions behave identically. No cap. Same thing, zero difference. ๐
But when you hand it a control socket of type REP, your app gets to send commands to the proxy and tell it what to do. Main character energy honestly. These are the commands that are supported:
๐ PAUSE ๐
The proxy stops transferring messages between its endpoints. It's giving "brb bestie" ๐ญ
๐ RESUME ๐
The proxy starts transferring messages between its endpoints again. We're so back. ๐ฅ
๐ TERMINATE ๐
The proxy function exits with a return value of 0. Bye queen ๐
๐ STATISTICS ๐
The proxy behavior stays exactly the same โ no changes, no drama โ and it replies with a set of simple summary values describing the messages that have been sent through the proxy, as described right below. โจ
There are eight statistics values, and each one is size uint64_t, living in the multi-part message reply to the STATISTICS command. They are:
- number of messages received by the frontend socket
- number of bytes received by the frontend socket
- number of messages sent by the frontend socket
- number of bytes sent by the frontend socket
- number of messages received by the backend socket
- number of bytes received by the backend socket
- number of messages sent by the backend socket
- number of bytes sent by the backend socket
๐ RETURN VALUE ๐
zmq_proxy_steerable() returns 0 if TERMINATE is received on its control socket. ๐
Otherwise it returns -1 and sets errno to one of these:
ETERMorEINTRโ the 0MQ context associated with either of the specified sockets was terminated ๐ญEFAULTโ the providedfrontendorbackendwas invalid ๐
๐ EXAMPLE ๐
First up: make a function to run the proxy.
// Create the frontend and backend sockets to be proxied
void *frontend = zmq_socket (context, ZMQ_ROUTER);
void *backend = zmq_socket (context, ZMQ_DEALER);
// Create the proxy control socket
void *control = zmq_socket (context, ZMQ_REP);
// Bind the sockets.
zmq_bind (frontend, "tcp://*:5555");
zmq_bind (backend, "tcp://*:5556");
zmq_bind (control, "tcp://*:5557");
zmq_proxy_steerable(frontend, backend, NULL, control);
Then, code in another thread/process to steer the proxy. ๐ฎ
void *control = zmq_socket (context, ZMQ_REQ);
zmq_connect (control, "tcp://*:5557");
zmq_msg_t msg;
zmq_send (control, "PAUSE", 5, 0);
zmq_msg_recv (&msg, control, 0));
zmq_send (control, "RESUME", 6, 0);
zmq_msg_recv (&msg, control, 0));
zmq_send (control, "STATISTICS", 10, 0);
while (1) {
zmq_msg_recv (&msg, control, 0));
printf(" %lu", *(uint64_t *)zmq_msg_data (&msg));
if (!zmq_msg_get (&msg, ZMQ_MORE))
break;
}
printf("\n");
zmq_send (control, "TERMINATE", 9, 0);
zmq_msg_recv (&msg, control, 0));
zmq_close(frontend);
zmq_close(backend);
zmq_close(control);
๐ง SEE ALSO ๐ง
zmq_proxy(3) zmq_bind(3) zmq_connect(3) zmq_socket(3) zmq(7)
๐ AUTHORS ๐
This page was written by the 0MQ community. ๐ซถ Wanna make a change? Please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing.
and that's the whole vibe, bestie โ this page was served fresh from 0MQ 4.3.5 on 10/09/2023. go slay some sockets ๐ โจ
๐ฆ 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