[英]how should I handle polling in ZMQ in node.js?
I'm working on building a Paranoid Pirate in node.js. 我正在用node.js构建偏执狂海盗。 Starting with some python code:
从一些python代码开始:
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. Go示例代码还使用了Poller。
The problem that I'm running into is that zeromq.node doesn't seem to use Pollers . 我遇到的问题是zeromq.node似乎没有使用Pollers 。 Is the solution in node to just use a callback on message?
节点中的解决方案是否仅在消息上使用回调? how should I handle the
POLLIN
state? 我应该如何处理
POLLIN
状态?
The Poller is redundant in node.js. Poller在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.
在节点上使用ZMQ要求对“传统” ZMQ方法和体系结构稍作更改,因为将所有非阻塞和事件处理的内置策略都卸载到了节点上,这自然地处理了这些工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.