Kafka-node: Count consumer group members/instances

Created on 4 Jun 2018  路  2Comments  路  Source: SOHU-Co/kafka-node

Environment

  • Node version: latest
  • Kafka-node version: 2.6.1
  • Kafka version: latest

Hi, there is a way to know or get Consumer Group members/consumers/instances?
i know there is an option in Kafka itself ('GroupMembers') but i need it in node.

thanks

question

Most helpful comment

If you are referring to https://kafka.apache.org/protocol#The_Messages_ListGroups then this can be achieved using the following code...

const options = { kafkaHost: 'localhost:9092' };
const client = new kafka.KafkaClient(options);
const admin = new kafka.Admin(client);
// listen to the 'ready' event on the client first, then...
admin.listGroups((err, res) => {
  let consumerGroups = Object.keys(res); // array of consumer group names
  let count = consumerGroups.length; // count of consumer group entries
});

https://github.com/SOHU-Co/kafka-node#describegroupsconsumergroups-cb can then be used to get more info on a group(s).

All 2 comments

If you are referring to https://kafka.apache.org/protocol#The_Messages_ListGroups then this can be achieved using the following code...

const options = { kafkaHost: 'localhost:9092' };
const client = new kafka.KafkaClient(options);
const admin = new kafka.Admin(client);
// listen to the 'ready' event on the client first, then...
admin.listGroups((err, res) => {
  let consumerGroups = Object.keys(res); // array of consumer group names
  let count = consumerGroups.length; // count of consumer group entries
});

https://github.com/SOHU-Co/kafka-node#describegroupsconsumergroups-cb can then be used to get more info on a group(s).

Good answer, thanks

Was this page helpful?
0 / 5 - 0 ratings