node.jsapache-kafkalibrdkafka

Consumer stops if stats is enabled - node-rdkafka


I am using node-rdkafka to consume messages from kafka. Consumer process exits if statistics.interval.ms is set.

Here is the code:

const { KafkaConsumer } = require('node-rdkafka')
const consumer = new KafkaConsumer(
    {
        'group.id': 'kafka',
        'metadata.broker.list': 'localhost:9092',
        'statistics.interval.ms': 5000,
    },
    {},
)
consumer
    .on('ready', () => {
        consumer.subscribe(['test1'])
        setInterval(() => {
            consumer.consume(1)
        }, 1000)
    })
    .on('data', (data) => {
        console.log('Message found!  Contents below.')
        console.log(data.value.toString())
    })
    .on('error', (e) => console.log(e))

This code just consumes one message and then exits. I checked process.on events as well but no error is thrown. If I remove 'statistics.interval.ms': 5000 then everything works fine


Solution

  • This is windows related problem. Linux works completely fine.