我正在尝试通过打开读取流并通过zmq将文件块发送到另一个过程来读取某些文件。该流的工作原理,但是当我启动工作人员时,它看不到已发送的数据。
我尝试每500ms,而不是在回调中发送数据
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
因此,当工人启动时,它是从拉动所有以前的数据开始的,然后每次sth new进来。
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..
在这种情况下,工人根本没有提取任何数据。这些插座是否应该创建队列?我在这里缺少什么?
是的,按钮插座一直阻塞,直到达到HWM为止,没有人可以发送到。也许发件人尚未绑定,尝试这样的事情:
sender.bind('address', function(err) {
if (err) throw err;
console.log('sender bound!');
// the readStream code.
}
您的代码示例中也缺少connect
,我敢打赌它在那里,但也许您忘记了它。