1ZMQ(7) 0MQ Manual ZMQ(7)
2
3
4
6 zmq - 0MQ lightweight messaging kernel
7
9 #include <zmq.h>
10
11 cc [flags] files -lzmq [libraries]
12
14 The 0MQ lightweight messaging kernel is a library which extends the
15 standard socket interfaces with features traditionally provided by
16 specialised messaging middleware products. 0MQ sockets provide an
17 abstraction of asynchronous message queues, multiple messaging
18 patterns, message filtering (subscriptions), seamless access to
19 multiple transport protocols and more.
20
21 This documentation presents an overview of 0MQ concepts, describes how
22 0MQ abstracts standard sockets and provides a reference manual for the
23 functions provided by the 0MQ library.
24
25 Context
26 The 0MQ context keeps the list of sockets and manages the async I/O
27 thread and internal queries.
28
29 Before using any 0MQ library functions you must create a 0MQ context.
30 When you exit your application you must destroy the context. These
31 functions let you work with contexts:
32
33 Create a new 0MQ context
34 zmq_ctx_new(3)
35
36 Work with context properties
37 zmq_ctx_set(3) zmq_ctx_get(3)
38
39 Destroy a 0MQ context
40 zmq_ctx_shutdown(3) zmq_ctx_term(3)
41
42 Thread safety
43 A 0MQ context is thread safe and may be shared among as many
44 application threads as necessary, without any additional locking
45 required on the part of the caller.
46
47 Individual 0MQ sockets are not thread safe except in the case where
48 full memory barriers are issued when migrating a socket from one
49 thread to another. In practice this means applications can create a
50 socket in one thread with zmq_socket() and then pass it to a newly
51 created thread as part of thread initialisation, for example via a
52 structure passed as an argument to pthread_create().
53
54 Multiple contexts
55 Multiple contexts may coexist within a single application. Thus, an
56 application can use 0MQ directly and at the same time make use of
57 any number of additional libraries or components which themselves
58 make use of 0MQ as long as the above guidelines regarding thread
59 safety are adhered to.
60
61 Messages
62 A 0MQ message is a discrete unit of data passed between applications or
63 components of the same application. 0MQ messages have no internal
64 structure and from the point of view of 0MQ itself they are considered
65 to be opaque binary data.
66
67 The following functions are provided to work with messages:
68
69 Initialise a message
70 zmq_msg_init(3) zmq_msg_init_size(3) zmq_msg_init_buffer(3)
71 zmq_msg_init_data(3)
72
73 Sending and receiving a message
74 zmq_msg_send(3) zmq_msg_recv(3)
75
76 Release a message
77 zmq_msg_close(3)
78
79 Access message content
80 zmq_msg_data(3) zmq_msg_size(3) zmq_msg_more(3)
81
82 Work with message properties
83 zmq_msg_gets(3) zmq_msg_get(3) zmq_msg_set(3)
84
85 Message manipulation
86 zmq_msg_copy(3) zmq_msg_move(3)
87
88 Sockets
89 0MQ sockets present an abstraction of an asynchronous message queue,
90 with the exact queueing semantics depending on the socket type in use.
91 See zmq_socket(3) for the socket types provided.
92
93 The following functions are provided to work with sockets:
94
95 Creating a socket
96 zmq_socket(3)
97
98 Closing a socket
99 zmq_close(3)
100
101 Manipulating socket options
102 zmq_getsockopt(3) zmq_setsockopt(3)
103
104 Establishing a message flow
105 zmq_bind(3) zmq_connect(3)
106
107 Sending and receiving messages
108 zmq_msg_send(3) zmq_msg_recv(3) zmq_send(3) zmq_recv(3)
109 zmq_send_const(3)
110
111 Monitoring socket events
112 zmq_socket_monitor(3)
113
114 Input/output multiplexing. 0MQ provides a mechanism for applications to
115 multiplex input/output events over a set containing both 0MQ sockets
116 and standard sockets. This mechanism mirrors the standard poll() system
117 call, and is described in detail in zmq_poll(3). This API is
118 deprecated, however.
119
120 There is a new DRAFT API with multiple zmq_poller_* function, which is
121 described in zmq_poller(3).
122
123 Transports
124 A 0MQ socket can use multiple different underlying transport
125 mechanisms. Each transport mechanism is suited to a particular purpose
126 and has its own advantages and drawbacks.
127
128 The following transport mechanisms are provided:
129
130 Unicast transport using TCP
131 zmq_tcp(7)
132
133 Reliable multicast transport using PGM
134 zmq_pgm(7)
135
136 Local inter-process communication transport
137 zmq_ipc(7)
138
139 Local in-process (inter-thread) communication transport
140 zmq_inproc(7)
141
142 Virtual Machine Communications Interface (VMC) transport
143 zmq_vmci(7)
144
145 Unreliable unicast and multicast using UDP
146 zmq_udp(7)
147
148 Proxies
149 0MQ provides proxies to create fanout and fan-in topologies. A proxy
150 connects a frontend socket to a backend socket and switches all
151 messages between the two sockets, opaquely. A proxy may optionally
152 capture all traffic to a third socket. To start a proxy in an
153 application thread, use zmq_proxy(3).
154
155 Security
156 A 0MQ socket can select a security mechanism. Both peers must use the
157 same security mechanism.
158
159 The following security mechanisms are provided for IPC and TCP
160 connections:
161
162 Null security
163 zmq_null(7)
164
165 Plain-text authentication using username and password
166 zmq_plain(7)
167
168 Elliptic curve authentication and encryption
169 zmq_curve(7)
170
171 Generate a CURVE keypair in armored text format
172 zmq_curve_keypair(3)
173
174 Derive a CURVE public key from a secret key: zmq_curve_public(3)
175
176 Converting keys to/from armoured text strings
177 zmq_z85_decode(3) zmq_z85_encode(3)
178
180 The 0MQ library functions handle errors using the standard conventions
181 found on POSIX systems. Generally, this means that upon failure a 0MQ
182 library function shall return either a NULL value (if returning a
183 pointer) or a negative value (if returning an integer), and the actual
184 error code shall be stored in the errno variable.
185
186 On non-POSIX systems some users may experience issues with retrieving
187 the correct value of the errno variable. The zmq_errno() function is
188 provided to assist in these cases; for details refer to zmq_errno(3).
189
190 The zmq_strerror() function is provided to translate 0MQ-specific error
191 codes into error message strings; for details refer to zmq_strerror(3).
192
194 The following utility functions are provided:
195
196 Working with atomic counters
197 zmq_atomic_counter_new(3) zmq_atomic_counter_set(3)
198 zmq_atomic_counter_inc(3) zmq_atomic_counter_dec(3)
199 zmq_atomic_counter_value(3) zmq_atomic_counter_destroy(3)
200
202 The following miscellaneous functions are provided:
203
204 Report 0MQ library version
205 zmq_version(3)
206
208 The 0MQ library provides interfaces suitable for calling from programs
209 in any language; this documentation documents those interfaces as they
210 would be used by C programmers. The intent is that programmers using
211 0MQ from other languages shall refer to this documentation alongside
212 any documentation provided by the vendor of their language binding.
213
214 Language bindings (C++, Python, PHP, Ruby, Java and more) are provided
215 by members of the 0MQ community and pointers can be found on the 0MQ
216 website.
217
219 This page was written by the 0MQ community. To make a change please
220 read the 0MQ Contribution Policy at
221 http://www.zeromq.org/docs:contributing.
222
224 Main web site: http://www.zeromq.org/
225
226 Report bugs to the 0MQ development mailing list:
227 <zeromq-dev@lists.zeromq.org[1]>
228
230 Free use of this software is granted under the terms of the GNU Lesser
231 General Public License (LGPL). For details see the files COPYING and
232 COPYING.LESSER included with the 0MQ distribution.
233
235 1. zeromq-dev@lists.zeromq.org
236 mailto:zeromq-dev@lists.zeromq.org
237
238
239
2400MQ 4.3.4 07/23/2021 ZMQ(7)