SOHU-Co / kafka-node

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

adding consumer to an existing group #1444

Open amirAlamian opened 3 years ago

amirAlamian commented 3 years ago

Hello. I am using your package to consume messages from kafka topics. I've created a group with kafka CLI using this command.

docker exec -it kafka1 kafka-console-consumer.sh --bootstrap-server kafka1:9092 --group test --topic test

then I've created a new consumer with your Consumer constructor. the code is:

const client = new KafkaClient({
  kafkaHost: 'kafka1:9092',
  autoConnect: true
});

const consumer = new Consumer(
  client,
[{topic:'test'}], 
{
    groupId: 'test'
  },
);
consumer.on('error', (err) => {
  console.log(`Error occurred on consumer group ${err}`);
});

consumer.on('message',  (message) => {
  console.log(message);
});

when I run this command in kafka CLI

docker exec -it kafka1 kafka-consumer-groups.sh --bootstrap-server kafka1:9092 --group test --describe

it says that there is no active member in this group. I've tried so many times and so many ways to make it work but the consumer never joined the group. after that I log my created consumer and the option part is says groupId: 'test' but it never show in the group.

what is the problem?