0

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

Mayank Kumar
  • 176
  • 1
  • 1
  • 14

2 Answers2

0

This is windows related problem. Linux works completely fine.

Mayank Kumar
  • 176
  • 1
  • 1
  • 14
0
consumer
    .on('ready', () => {
        consumer.subscribe(['test1'])
            consumer.consume()
    })
    .on('data', (data) => {
        console.log('Message found!  Contents below.')
        console.log(data.value.toString())
    })
    .on('error', (e) => console.log(e))

Try this and let me know if it work for you.

Jabbar Memon
  • 83
  • 1
  • 5