zmq.txt 8.0 KB

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