[英]Nodejs kafka consumer infinite loop
我在Ubuntu 16.04机器上运行kafka_2.11-2.0.0。 创建了一个主题,并从命令行界面向其生成了一些消息。
并从命令行启动了消费者,这很好。
但是当我像下面那样启动nodejs消费者时,它是无限迭代的。 客户代码中缺少什么吗?
var kafka = require('kafka-node'),
Consumer = kafka.Consumer,
client = new kafka.Client(),
consumer = new Consumer(
client,
[
{topic: 'mytopic', partition: 0}
],
{
autoCommit: true
}
);
consumer.on('message', function (message) {
console.log(message);
});
consumer.on('error', function (err){
console.log(err);
})
consumer.on('offsetOutOfRange', function (err){
console.log(err);
process.exit();
})
这是输出。
{ topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' } { topic: 'mytopic', value: 'message2', offset: 1, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: 'message3', offset: 2, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' } { topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' } { topic: 'mytopic', value: 'message2', offset: 1, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: 'message3', offset: 2, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' } { topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' } { topic: 'mytopic', value: 'message2', offset: 1, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: 'message3', offset: 2, partition: 0, highWaterOffset: 3, key: null } { topic: 'mytopic', value: '', offset: 0, partition: 0, highWaterOffset: 3, key: '' }
最终发现kafka新版本2.0.0的问题。 因此,我移至以前的版本,并且现在可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.