1ZMQ_PROXY_STEERABLE(3)            0MQ Manual            ZMQ_PROXY_STEERABLE(3)
2
3
4

NAME

6       zmq_proxy_steerable - built-in 0MQ proxy with control flow
7

SYNOPSIS

9       int zmq_proxy_steerable (const void *frontend, const void *backend,
10       const void *capture, const void *control);
11

DESCRIPTION

13       The zmq_proxy_steerable() function starts the built-in 0MQ proxy in the
14       current application thread, as zmq_proxy() do. Please, refer to this
15       function for the general description and usage. We describe here only
16       the additional control flow provided by the socket passed as the fourth
17       argument "control".
18
19       If the control socket is not NULL, the proxy supports control flow. If
20       PAUSE is received on this socket, the proxy suspends its activities. If
21       RESUME is received, it goes on. If TERMINATE is received, it terminates
22       smoothly. If STATISTICS is received, the proxy will reply on the
23       control socket sending a multipart message with 8 frames, each with an
24       unsigned integer 64-bit wide that provide in the following order: -
25       number of messages received by the frontend socket - number of bytes
26       received by the frontend socket - number of messages sent out the
27       frontend socket - number of bytes sent out the frontend socket - number
28       of messages received by the backend socket - number of bytes received
29       by the backend socket - number of messages sent out the backend socket
30       - number of bytes sent out the backend socket
31
32       At start, the proxy runs normally as if zmq_proxy was used.
33
34       If the control socket is NULL, the function behave exactly as if
35       zmq_proxy(3) had been called.
36
37       Refer to zmq_socket(3) for a description of the available socket types.
38       Refer to zmq_proxy(3) for a description of the zmq_proxy.
39

EXAMPLE USAGE

41       cf zmq_proxy
42

RETURN VALUE

44       The zmq_proxy_steerable() function returns 0 if TERMINATE is sent to
45       its control socket. Otherwise, it returns -1 and errno set to ETERM or
46       EINTR (the 0MQ context associated with either of the specified sockets
47       was terminated) or EFAULT (the provided frontend or backend was
48       invalid).
49

EXAMPLE

51       Creating a shared queue proxy.
52
53           //  Create frontend, backend and control sockets
54           void *frontend = zmq_socket (context, ZMQ_ROUTER);
55           assert (frontend);
56           void *backend = zmq_socket (context, ZMQ_DEALER);
57           assert (backend);
58           void *control = zmq_socket (context, ZMQ_SUB);
59           assert (control);
60
61           //  Bind sockets to TCP ports
62           assert (zmq_bind (frontend, "tcp://*:5555") == 0);
63           assert (zmq_bind (backend, "tcp://*:5556") == 0);
64           assert (zmq_connect (control, "tcp://*:5557") == 0);
65
66           // Subscribe to the control socket since we have chosen SUB here
67           assert (zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0));
68
69           //  Start the queue proxy, which runs until ETERM or "TERMINATE"
70           //  received on the control socket
71           zmq_proxy_steerable (frontend, backend, NULL, control);
72
73       Set up a controller in another node, process or whatever.
74
75           void *control = zmq_socket (context, ZMQ_PUB);
76           assert (control);
77           assert (zmq_bind (control, "tcp://*:5557") == 0);
78
79           // pause the proxy
80           assert (zmq_send (control, "PAUSE", 5, 0) == 0);
81
82           // resume the proxy
83           assert (zmq_send (control, "RESUME", 6, 0) == 0);
84
85           // terminate the proxy
86           assert (zmq_send (control, "TERMINATE", 9, 0) == 0);
87
88           // check statistics
89           assert (zmq_send (control, "STATISTICS", 10, 0) == 0);
90           zmq_msg_t stats_msg;
91
92           while (1) {
93               assert (zmq_msg_init (&stats_msg) == 0);
94               assert (zmq_recvmsg (control, &stats_msg, 0) == sizeof (uint64_t));
95               assert (rc == sizeof (uint64_t));
96               printf ("Stat: %lu\n", *(unsigned long int *)zmq_msg_data (&stats_msg));
97               if (!zmq_msg_get (&stats_msg, ZMQ_MORE))
98                   break;
99               assert (zmq_msg_close (&stats_msg) == 0);
100           }
101           assert (zmq_msg_close (&stats_msg) == 0);
102           ---
103
104
105           SEE ALSO
106
107       zmq_proxy(3) zmq_bind(3) zmq_connect(3) zmq_socket(3) zmq(7)
108

AUTHORS

110       This page was written by the 0MQ community. To make a change please
111       read the 0MQ Contribution Policy at
112       http://www.zeromq.org/docs:contributing.
113
114
115
1160MQ 4.3.4                         07/22/2023            ZMQ_PROXY_STEERABLE(3)
Impressum