I am running kafka_2.11-2.0.0 on ubuntu 16.04 machine. Created a topic and produced some messages to it from command line interface.
And started consumer from command line, it's consuming well.
But when I started nodejs consumer like below, it's infinitely iterating. Is there anything I was missing in my client code?
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();
})
Here is the output.
{ 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: '' }
Finally found that the issue with kafka new release 2.0.0. So I moved to previous version and it's working now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.