2
votes

When i run kafka-console-consumer like so

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

What consumer group does it default to? Does it end up using a random consumer group if I don't specify consumer group or link to consumer properties in the command line? How can I check what consumer group was used?

Thanks!

2

2 Answers

5
votes

If a group is not specified, the kafka-console-consumer.sh generates a random consumer group with this format:

console-consumer-${new Random().nextInt(100000)}

See the ConsoleConsumer scala class: https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/tools/ConsoleConsumer.scala#L370

Unfortunately to find the generated group id, you have to:

  • look at the console consumer logs
  • list all groups (for example using the kafka-consumer-groups tool and filter for group starting with console-consumer-.
1
votes

It uses a random one, that's not intended to be reused, so there should be no reason to know what it is because it'll be cleaned up when the consumer object is closed

consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, s"console-consumer-${new Random().nextInt(100000)}")
    // By default, avoid unnecessary expansion of the coordinator cache since
    // the auto-generated group and its offsets is not intended to be used again
    if (!consumerProps.containsKey(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG))
      consumerProps.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false")