zmq_proxy.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. zmq_proxy(3)
  2. ============
  3. NAME
  4. ----
  5. zmq_proxy - start built-in 0MQ proxy
  6. SYNOPSIS
  7. --------
  8. *int zmq_proxy (void '*frontend', void '*backend', void '*capture');*
  9. DESCRIPTION
  10. -----------
  11. The _zmq_proxy()_ function starts the built-in 0MQ proxy in the current
  12. application thread.
  13. The proxy connects a frontend socket to a backend socket. Conceptually, data
  14. flows from frontend to backend. Depending on the socket types, replies may flow
  15. in the opposite direction. The direction is conceptual only; the proxy is fully
  16. symmetric and there is no technical difference between frontend and backend.
  17. Before calling _zmq_proxy()_ you must set any socket options, and connect or
  18. bind both frontend and backend sockets. The two conventional proxy models are:
  19. _zmq_proxy()_ runs in the current thread and returns only if/when the current
  20. context is closed.
  21. If the capture socket is not NULL, the proxy shall send all messages, received
  22. on both frontend and backend, to the capture socket. The capture socket should
  23. be a 'ZMQ_PUB', 'ZMQ_DEALER', 'ZMQ_PUSH', or 'ZMQ_PAIR' socket.
  24. Refer to linkzmq:zmq_socket[3] for a description of the available socket types.
  25. EXAMPLE USAGE
  26. -------------
  27. Shared Queue
  28. ~~~~~~~~~~~~
  29. When the frontend is a ZMQ_ROUTER socket, and the backend is a ZMQ_DEALER
  30. socket, the proxy shall act as a shared queue that collects requests from a
  31. set of clients, and distributes these fairly among a set of services.
  32. Requests shall be fair-queued from frontend connections and distributed evenly
  33. across backend connections. Replies shall automatically return to the client
  34. that made the original request.
  35. Forwarder
  36. ~~~~~~~~~
  37. When the frontend is a ZMQ_XSUB socket, and the backend is a ZMQ_XPUB socket,
  38. the proxy shall act as a message forwarder that collects messages from a set
  39. of publishers and forwards these to a set of subscribers. This may be used to
  40. bridge networks transports, e.g. read on tcp:// and forward on pgm://.
  41. Streamer
  42. ~~~~~~~~
  43. When the frontend is a ZMQ_PULL socket, and the backend is a ZMQ_PUSH socket,
  44. the proxy shall collect tasks from a set of clients and forwards these to a set
  45. of workers using the pipeline pattern.
  46. RETURN VALUE
  47. ------------
  48. The _zmq_proxy()_ function always returns `-1` and 'errno' set to *ETERM* or
  49. *EINTR* (the 0MQ 'context' associated with either of the specified sockets was
  50. terminated).
  51. EXAMPLE
  52. -------
  53. .Creating a shared queue proxy
  54. ----
  55. // Create frontend and backend sockets
  56. void *frontend = zmq_socket (context, ZMQ_ROUTER);
  57. assert (backend);
  58. void *backend = zmq_socket (context, ZMQ_DEALER);
  59. assert (frontend);
  60. // Bind both sockets to TCP ports
  61. assert (zmq_bind (frontend, "tcp://*:5555") == 0);
  62. assert (zmq_bind (backend, "tcp://*:5556") == 0);
  63. // Start the queue proxy, which runs until ETERM
  64. zmq_proxy (frontend, backend, NULL);
  65. ----
  66. SEE ALSO
  67. --------
  68. linkzmq:zmq_bind[3]
  69. linkzmq:zmq_connect[3]
  70. linkzmq:zmq_socket[3]
  71. linkzmq:zmq[7]
  72. AUTHORS
  73. -------
  74. This page was written by the 0MQ community. To make a change please
  75. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.