Skip to content

Instantly share code, notes, and snippets.

@davipt davipt/gist:7361477
Created Nov 7, 2013

What would you like to do?
zmq proxy sample
// Simple message queuing broker
// Same as request-reply broker but using QUEUE device
#include "zhelpers.h"
int main (int argc, char* argv[]) {
int t = argc>3 ? atoi(argv[3]):0;
if(t == 1)
printf("Proxy type=PULL/PUSH in=%s out=%s\n", argv[1], argv[2]);
else if(t == 2)
printf("Proxy type=ROUTER/DEALER in=%s out=%s\n", argv[1], argv[2]);
printf("Proxy type=XSUB/XPUB in=%s out=%s\n", argv[1], argv[2]);
void *context = zmq_ctx_new ();
// Socket facing clients
void *frontend = zmq_socket (context, t==1?ZMQ_PULL:t==2?ZMQ_ROUTER:ZMQ_XSUB);
int rc = zmq_bind (frontend, argv[1]);
assert (rc == 0);
// Socket facing services
void *backend = zmq_socket (context, t==1?ZMQ_PUSH:t==2?ZMQ_DEALER:ZMQ_XPUB);
rc = zmq_bind (backend, argv[2]);
assert (rc == 0);
// Start the proxy
zmq_proxy (frontend, backend, NULL);
// We never get here...
zmq_close (frontend);
zmq_close (backend);
zmq_ctx_destroy (context);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.