我正在尝试通过打开读取流来读取某个文件,并通过ZMQ将文件块发送到另一个进程来使用它们。流正在运行,但是当我启动worker时,它看不到已发送的数据。
我尝试每隔500毫秒通过套接字发送数据,而不是在回调中,当我启动工作时,它会收集所有以前的数据块:
sender = zmq.socket('push')
setInterval(() ->
console.log('sending work');
sender.send('some work')
, 500)
receiver = zmq.socket("pull")
receiver.on "message", (msg) ->
console.log('work is here: %s', msg.toString())
输出:
sending work
sending work
sending work
sending work
sending work
// here I start the worker
sending work
work is here: some work
work is here: some work
work is here: some work
work is here: some work
work is here: some work
work is here: some work
sending work
work is here: some work
sending work
work is here: some work
sending work
work is here: some work
因此,当工作人员启动时,它会从拉动所有先前的数据开始,然后每次进入时都会将其拉出。这在我执行此操作时不适用:
readStream = fs.createReadStream("./data/pg2701.txt", {'bufferSize': 100 * 1024})
readStream.on "data", (data) ->
console.log('sending work');
sender.send('some work'); // I'd send 'data' if it worked..
在这种情况下,工作人员根本不会提取任何数据。 这些套接字是否应该创建队列?我在这里缺少什么?
答案 0 :(得分:0)
是的,推送套接字阻塞,直到达到HWM,并且无人发送。 也许发件人尚未约束,尝试这样的事情:
sender.bind('address', function(err) {
if (err) throw err;
console.log('sender bound!');
// the readStream code.
}
你的代码示例中也缺少connect
,我打赌它在那里,但也许你忘了它。