user2290820
user2290820

Reputation: 2749

How to detect a REQ connect event to ROUTER

What I want?

Whenever the REQ connects with requester.connect() call to that host:port, ROUTER should detect this event and do something i.e. in this case cluster.fork();

I tried:

       //Start Evented Child Node Processes alongwith a Request REQ Each
        router.on("accept", function funcCB (fileDesc, endPt) {
            //fire up a cluster fork for handling Requests
            console.log("starting a new FORK process");
            cluster.fork();
        });

What router.on(<event>) should actually detect a

requester.connect()

??

As per this here these are the monitor events available for node zmq:

These are the triggered events as per the doc there:

connect - ZMQ_EVENT_CONNECTED
connect_delay - ZMQ_EVENT_CONNECT_DELAYED
connect_retry - ZMQ_EVENT_CONNECT_RETRIED
listen - ZMQ_EVENT_LISTENING
bind_error - ZMQ_EVENT_BIND_FAILED
accept - ZMQ_EVENT_ACCEPTED
accept_error - ZMQ_EVENT_ACCEPT_FAILED
close - ZMQ_EVENT_CLOSED
close_error - ZMQ_EVENT_CLOSE_FAILED
disconnect - ZMQ_EVENT_DISCONNECTED

Upvotes: 1

Views: 372

Answers (2)

user2290820
user2290820

Reputation: 2749

So the answer was this small addition as posted by @Jason here on the SO comments section

//start the socket ROUTER monitor
            router.monitor(500, 0);

Upvotes: 0

user3666197
user3666197

Reputation: 1

How it works?

The beauty of ZeroMQ is in it's architecture. This means, the abstract scaleable archetype primitives ( PUB / SUB, PAIR, XREQ ) do exactly what these have been defined for.

The clean architecture separates I/O-thread(s) from socket's-entry-gate "behaviour" and keeps all the dirty stuff down there:: enter image description here

This said, it is of no use say I want ROUTER to detect and handle also this and that, if it was not defined to do this right in the ZeroMQ architecture.

How to do it?

The simplest approach to this and similar need is to design one's own composite element, let's for the simplicity sketch it as [[ROUTER]+[SUB]], where the node has both the [ROUTER]-trafic-oriented behaviour and also keeps a [SUB]-signalling-receiving behaviour, exposed to outer world via SUB.bind() at another host:portSIG

This way, remote processes REQ.connect( host:port) and PUB.connect( host:portSIG ) and operate on both the transport-plane and the signalling-plane as your design needs and implements.

ZeroMQ is a lovely can-do LEGO-toolbox. enter image description here Enjoy these powers.

Upvotes: 1

Related Questions