如何在Kafka的命令行中获取主题的group.id?

Fra*_*ung 4 apache-kafka

我在服务器上安装了kafka,并想学习如何使用它,找到了scala编写的示例代码,下面是其中的一部分,

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
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在服务器上找到组ID。

Lun*_*ahl 6

该group id是你自己定义为你的消费者通过东西为它提供一个字符串ID。以相同ID开头的所有使用者将以协作的方式“协作”并阅读主题,其中每个使用者实例将处理主题中消息的子集。提供不存在的组ID将被视为新使用者,并在Zookeeper中创建新条目,其中将存储已提交的偏移量。


Mar*_*aci 5

您可以获得 Zookeeper shell 并列出 Kafka 存储消费者偏移量的路径,如下所示:

./bin/zookeeper-shell.sh localhost:2181
ls /consumers
Run Code Online (Sandbox Code Playgroud)

您将获得所有组的列表。

编辑:我错过了您所说的您自己设置的部分,所以我认为您想要列出现有集群的消费者组。
Lundahl 是对的,这是您定义的一个属性,用于协调消费者线程,以便它们不会消耗“彼此的”消息(每个消耗一个子集)。例如,如果您使用 2 个具有不同组的消费者,他们将各自使用整个主题。