jcollum
jcollum

Reputation: 46569

how should I handle polling in ZMQ in node.js?

I'm working on building a Paranoid Pirate in node.js. Starting with some python code:

poller = zmq.Poller()

liveness = HEARTBEAT_LIVENESS
interval = INTERVAL_INIT

heartbeat_at = time.time() + HEARTBEAT_INTERVAL

worker = worker_socket(context, poller)
cycles = 0
while True:
    socks = dict(poller.poll(HEARTBEAT_INTERVAL * 1000))

    # Handle worker activity on backend
    if socks.get(worker) == zmq.POLLIN:
        #  Get message
        #  - 3-part envelope + content -> request
        #  - 1-part HEARTBEAT -> heartbeat
        frames = worker.recv_multipart()

The Go sample code also uses a Poller.

The problem that I'm running into is that zeromq.node doesn't seem to use Pollers. Is the solution in node to just use a callback on message? how should I handle the POLLIN state?

Upvotes: 2

Views: 771

Answers (1)

Jason
Jason

Reputation: 13766

The Poller is redundant in node.js. It's all just callbacks on message receipts. Using ZMQ in node requires a slight shift in the "traditional" ZMQ methods and architectures, because all of the built in strategies for non-blocking and event handling are offloaded to node, which deals with that stuff naturally.

Upvotes: 2

Related Questions