ZMQ::Raw::Proxy - ZeroMQ Proxy class


version 0.39


ZeroMQ Proxy


        use ZMQ::Raw;
        use threads;

        my $ctx = ZMQ::Raw::Context->new;

        sub Proxy
                my $frontend = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_ROUTER);
                $frontend->bind ('tcp://*:5555');

                my $backend = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_DEALER);
                $backend->bind ('tcp://*:5556');

                my $proxy = ZMQ::Raw::Proxy->new();
                $proxy->start ($frontend, $backend);

        # start the proxy in a different thread
        my $proxy = threads->create ('Proxy');

        my $req = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_REQ);
        $req->connect ('tcp://');

        my $rep = ZMQ::Raw::Socket->new ($ctx, ZMQ::Raw->ZMQ_REP);
        $rep->connect ('tcp://');

        # interact
        $req->send ('hello');

        $rep->send ('world');



new( )

Create a new proxy instance.

start( $frontend, $backend, [$capture, $control] )

Start the built-in ZeroMQ proxy in the current application thread. The proxy connects the frontend socket to the backend socket. If a $capture socket is provided, the proxy shall send all messages, received on both frontend and backend to the $capture socket. If a $control socket is provided, the proxy also supports flow control. If "PAUSE" is received on this socket, the proxy suspends its activities. If "RESUME" is received, it goes on. If "TERMINATE" is received, it terminates smoothly.

WARNING: This method will only return once the current context is closed, that is, it will block. This method must be called in a different interpreter thread.


Jacques Germishuys <>


Copyright 2017 Jacques Germishuys.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.