How can I get the group.id of a topic in command line in Kafka?

23,514

Solution 1

The group id is something you define yourself for your consumer by providing a string id for it. All consumers started with the same id will "cooperate" and read topics in a coordinated way where each consumer instance will handle a subset of the messages in a topic. Providing a non-existent group id will be considered to be a new consumer and create a new entry in Zookeeper where committed offsets will be stored.

Solution 2

You could get a Zookeeper shell and list path where Kafka stores consumers' offsets like this:

./bin/zookeeper-shell.sh localhost:2181
ls /consumers

You'll get a list of all groups.

EDIT: I missed the part where you said that you're setting this up yourself so I thought that you want to list the consumer groups of an existing cluster.
Lundahl is right, this is a property that you define, which is used to coordinate consumer threads so that they don't consume "each other's" messages (each consumes a subset). If you, for example, use 2 consumers with different groups, they'll each consume the whole topic.

Solution 3

/kafkadir/kafka-consumer-groups.sh --all-topics --bootstrap-server hostname:port --list

Share:
23,514
Frank Yeung
Author by

Frank Yeung

Updated on September 16, 2021

Comments

  • Frank Yeung
    Frank Yeung over 2 years

    I installed kafka on my server and want to learn how to use it, I found a sample code written by scala, below is part of it,

    def createConsumerConfig(zookeeper: String, groupId: String): ConsumerConfig = {
        val props = new Properties()
        props.put("zookeeper.connect", zookeeper)
        props.put("group.id", groupId)
        props.put("auto.offset.reset", "largest")
        props.put("zookeeper.session.timeout.ms", "400")
        props.put("zookeeper.sync.time.ms", "200")
        props.put("auto.commit.interval.ms", "1000")
        val config = new ConsumerConfig(props)
        config
    }
    

    but I don't know how to find the group id on my server.