SOHU-Co / kafka-node

Node.js client for Apache Kafka 0.8 and later.
MIT License
2.66k stars 628 forks source link

ConsumerGroup does not comsume data from all partitions #882

Open emmaccacca opened 6 years ago

emmaccacca commented 6 years ago

Questions?

I use HighLevelProducer to produce keyed message and then I use ConsumerGroup to consume messages. But I only get message of one or two partitions every time I restart my service.

I have a question. How can I ensure the order of messages ussing HighLevelProducer and ConsumerGroup?

Bug Report

Environment

For specific cases also provide

Include Sample Code to reproduce behavior

const client = new Client({
    kafkaHost
});
const producer = new Producer(client);

producer.send([{
    topic: 'topic',
    messages: new KeyedMessage('key', 'message')
}], (err, data) => {
    if (err) {
        console.error(err);
    }
});

const consumerOptions = {
    kafkaHost,
    groupId: 'log',
    autoCommit: false,
    fromOffset: 'earliest'
};

const consumer = new Consumer(consumerOptions, ['topic']);

Include output with Debug turned on

Thanks for your contribution!

aikar commented 6 years ago

As I responded on https://github.com/SOHU-Co/kafka-node/issues/904 - Considering your import is named "Consumer", and not "ConsumerGroup", I assume you imported from lib/consumer.js

If this is the case, you need to use ConsumerGroup (lib/consumerGroup.js) instead, if you want all partitions to be automatically assigned. Consumer requires manually specifying partitions.

@hyperlink I can see why this is a source of confusion considering the docs list Consumer first, but still uses a group ID in config.

Maybe need to update docs to say 'You probably want '

hyperlink commented 6 years ago

You're right @aikar there's certainly improvement opportunities in the docs.