ZeroMQ API (6) Agent

1、zmq_proxy(3)

1.1 Name

  zmq_proxy - Start built-in ZMQ proxy

1.2 Overview

  int zmq_proxy(const void * frontend,const void * backend,const void * capture);

1.3 Description

  The zmq_proxy() function starts the built-in ZMQ proxy in the current application thread.

  The proxy connects the frontend socket to the backend socket. Conceptually, data flows from the front end to the back end. Depending on the socket type, replies may flow in the opposite direction. The direction is only conceptual; the proxy is completely symmetrical, and there is no technical difference between the front-end and the back-end.

  Before calling zmq_proxy(), you must set any socket options, and connect or bind the front-end and back-end sockets. The two traditional proxy models are:

  zmq_proxy() runs in the current thread and only returns when the current context is closed.

  If the capture socket is not NULL, the broker should send all messages received on the frontend and backend to the capture socket. The capture socket should be a ZMQ_PUB, ZMQ_DEALER, ZMQ_PUSH or ZMQ_PAIR socket.

  See zmq_socket(3) for a description of the available socket types.

1.4 Usage example

1.4.1 Shared Queue

  When the frontend is a ZMQ_ROUTER socket and the backend is a ZMQ_DEALER socket, the broker will act as a shared queue to collect requests from a set of clients and distribute them fairly among a set of services. Requests should be queued fairly from frontend connections and evenly distributed among backend connections. A reply will automatically be returned to the client that made the original request.

1.4.2 Forwarding

  When the front end is a ZMQ_XSUB socket and the back end is a ZMQ_XPUB socket, the broker will act as a message forwarder to collect messages from a set of publishers and forward those messages to a set of subscribers. This can be used to bridge network transports, for example, to read tcp:// and forward on pgm://.

1.4.3 Streams

  When the frontend is a ZMQ_PULL socket and the backend is a ZMQ_PUSH socket, the proxy server should collect tasks from a set of clients and forward those tasks to a set of workers using pipeline mode.

1.4.4 Return value

  The zmq_proxy() function always returns -1 with errno set to ETERM (the ZMQ context associated with either specified socket has terminated).

2、zmq_proxy_steerable()

2.1 Name

  zmq_proxy_steerable - built-in ZMQ proxy with control flow

2.2 Overview

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

2.3 Description

  The zmq_proxy_steerable() function starts the built-in ZMQ proxy in the current application thread, as zmq_proxy() does. See the general description and usage of this feature. We only describe here the additional control flow provided by the socket passed as the fourth parameter "control".

  If the control socket is not NULL, the proxy supports control flow. If a PAUSE is received on this socket, the broker will suspend its activity. If RESUME is received, it will continue. If a TERMINATE is received, it will terminate gracefully. At the beginning, the proxy works fine, just like with zmq_proxy.

  If the control socket is NULL, the function behaves exactly as it would when calling zmq_proxy.

  See zmq_socket(3) for a description of the available socket types. See zmq_proxy(3) for a description of zmq_proxy.

2.4 Usage example

  Compare zmq_proxy

2.5 Return value

  The zmq_proxy_steerable() function returns 0 if TERMINATE is sent to its controlling socket. Otherwise, it returns -1 and sets errno to ETERM (the ZMQ context associated with either specified socket has terminated).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324986723&siteId=291194637