zproxy(3)

zproxy(3)

CZMQ Manual - CZMQ/2.2.1

Name

zproxy - run a steerable proxy in the background

Synopsis

//  Constructor
//  Create a new zproxy object. You must create the frontend and backend
//  sockets, configure them, and connect or bind them, before you pass them
//  to the constructor. Do NOT use the sockets again, after passing them to
//  this method.
CZMQ_EXPORT zproxy_t *
    zproxy_new (zctx_t *ctx, void *frontend, void *backend);

//  Destructor
//  Destroy a zproxy object; note this first stops the proxy.
CZMQ_EXPORT void
    zproxy_destroy (zproxy_t **self_p);

//  Copy all proxied messages to specified endpoint; if this is NULL, any
//  in-progress capturing will be stopped. You must already have bound the
//  endpoint to a PULL socket.
CZMQ_EXPORT void
    zproxy_capture (zproxy_t *self, const char *endpoint);

//  Pauses a zproxy object; a paused proxy will cease processing messages,
//  causing them to be queued up and potentially hit the high-water mark on
//  the frontend socket, causing messages to be dropped, or writing
//  applications to block.
CZMQ_EXPORT void
    zproxy_pause (zproxy_t *self);

//  Resume a zproxy object
CZMQ_EXPORT void
    zproxy_resume (zproxy_t *self);

// Self test of this class
CZMQ_EXPORT void
    zproxy_test (bool verbose);

Description

The zproxy class provides an equivalent to the ZMQ steerable proxy, on all versions of ZeroMQ.

Example

From zproxy_test method

 zctx_t *ctx = zctx_new ();
 void *frontend = zsocket_new (ctx, ZMQ_PULL);
 int rc = zsocket_bind (frontend, "inproc://frontend");
 assert (rc == 0);
 void *backend = zsocket_new (ctx, ZMQ_PUSH);
 rc = zsocket_bind (backend, "inproc://backend");
 assert (rc == 0);
 zproxy_t *proxy = zproxy_new (ctx, frontend, backend);

 // Connect application sockets to proxy
 void *faucet = zsocket_new (ctx, ZMQ_PUSH);
 rc = zsocket_connect (faucet, "inproc://frontend");
 assert (rc == 0);
 void *sink = zsocket_new (ctx, ZMQ_PULL);
 rc = zsocket_connect (sink, "inproc://backend");
 assert (rc == 0);

 // Send some messages and check they arrived
 zstr_send (faucet, "Hello");
 char *string = zstr_recv (sink);
 assert (streq (string, "Hello"));
 zstr_free (&string);

 // Check pause/resume functionality
 zproxy_pause (proxy);
 zstr_send (faucet, "World");

 zproxy_resume (proxy);
 string = zstr_recv (sink);
 assert (streq (string, "World"));
 zstr_free (&string);

 // Create capture socket, must be a PULL socket
 void *capture = zsocket_new (ctx, ZMQ_PULL);
 rc = zsocket_bind (capture, "inproc://capture");
 assert (rc == 0);

 // Switch on capturing, check that it works
 zproxy_capture (proxy, "inproc://capture");
 zstr_send (faucet, "Hello");

 string = zstr_recv (sink);
 assert (streq (string, "Hello"));
 zstr_free (&string);

 string = zstr_recv (capture);
 assert (streq (string, "Hello"));
 zstr_free (&string);
 zproxy_destroy (&proxy);  zctx_destroy (&ctx);

See also

czmq(7)

Authors

The CZMQ manual was written by Pieter Hintjens<moc.xitami|hp#moc.xitami|hp>.

Resources

Main web site: http://czmq.zeromq.org/

Report bugs to the ØMQ development mailing list: <gro.qmorez.stsil|ved-qmorez#gro.qmorez.stsil|ved-qmorez>

Copyright

Copyright (c) 1991-2014 iMatix and Contributors. License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to change it and redistribute it. There is NO WARRANTY, to the extent permitted by law. For details see the files COPYING and COPYING.LESSER included with the CZMQ distribution.