node-kafka pause() method on consumer. Any working version?

Viewed 1806

I can't make following code to work:

"use strict";

let kafka = require('kafka-node');
var conf = require('./providers/Config');

let client = new kafka.Client(conf.kafka.connectionString, conf.kafka.clientName);
let consumer = new kafka.HighLevelConsumer(client, [ { topic: conf.kafka.readTopic } ], { groupId: conf.kafka.clientName, paused: true });

let threads = 0;

consumer.on('message', function(message) {
    threads++;

    if (threads > 10) consumer.pause();

    if (threads > 50) process.exit(1);

    console.log(threads + " >>> " + message.value);
});

consumer.resume();

I see 50 messages in console and process exits by termination statement.

What I'm trying to understand, is that is it my code broken or package broken? Or maybe I'm just doing something wrong? Does anyone was able to make kafka consumer work with pause/resume? I tried several versions of kafka-node, but all of them behave same way. Thanks!

1 Answers
Related