首页 > 其他分享 >kafka-consumer-groups 命令行工具使用手册,Kafka 管理必备

kafka-consumer-groups 命令行工具使用手册,Kafka 管理必备

时间:2022-11-12 21:00:34浏览次数:61  
标签:group -- chenjing kafka 使用手册 groups consumer

kafka-consumer-groups 命令行工具使用手册

该手册原文出自 ​​$KAFKA_HOME\bin\windows\kafka-consumer-groups.bat --help​​ 命令的输出结果,并由 ​​Redisant​​ 提供翻译和测试用例。

--all-groups

Apply to all consumer groups.

指定所有的消费者组。 和 ​​--describe​​, ​​--delete​​, ​​--reset-offsets​​, ​​--delete-offsets​​ 配合使用

--all-topics

Consider all topics assigned to a group in the ​​reset-offsets​​ process.

指定所有的消费者组。 和 ​​--reset-offsets​​ 配合使用

--bootstrap-server

REQUIRED: The server(s) to connect to.

必填项,Kafka服务器的地址和端口。

--by-duration

Reset offsets to offset by duration from current timestamp. Format: 'PnDTnHnMnS'

--command-config

Property file containing configs to be passed to Admin Client and Consumer.

--delete

Pass in groups to delete topic partition offsets and ownership information over the entire consumer group. For instance --group g1 --group g2

删除整个消费者组(包括已保存的偏移量信息和所有权信息),在执行该操作之前,必须关闭所有的消费者。

  • 删除所有的消费者组
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups CountryCounter --delete
Deletion of requested consumer groups ('CountryCounter', 'OrderCounter') was successful.
  • 删除指定的消费者组
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --delete
Deletion of requested consumer groups ('CountryCounter') was successful.

--delete-offsets

Delete offsets of consumer group. Supports one consumer group at the time, and multiple topics.

删除消费者组的偏移量。例如:

PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --delete-offsets --group CountryCounter --topic t1

--describe

Describe consumer group and list offset lag (number of messages not yet processed) related to given group.

列出消费者组里所有主题的信息和每个分区的偏移量。例如:

  • 查看指定的消费者组:
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe

GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
CountryCounter user_card 0 214 214 0 chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
CountryCounter t1 0 189 189 0 chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
  • 查看所有的消费者组:
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe

GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
CountryCounter user_card 0 214 214 0 chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
CountryCounter t1 0 189 189 0 chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client

GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
OrderCounter t1 0 189 189 0 client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2
OrderCounter t2 0 1257 1257 0 client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2

--group

The consumer group we wish to act on.

配合其他命令执行消费者组

--help

Print usage information.

打印帮助手册

--list

List all consumer groups.

列出所有的消费者组。例如:

PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --list
OrderCounter
CountryCounter

--members

Describe members of the group. This option may be used with '--describe' and '--bootstrap-server' options only. Example: --bootstrap-server localhost:9092 --describe --group group1 --members

查看消费者组里有哪些成员,该选项只能和 ​​--describe​​ 和 ​​--bootstrap-server​​ 一起使用。例如:

  • 查看指定的消费者组里有哪些成员
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe --members

GROUP CONSUMER-ID HOST CLIENT-ID #PARTITIONS
CountryCounter chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client 2
  • 查看所有的消费者组里有哪些成员
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe --members

GROUP CONSUMER-ID HOST CLIENT-ID #PARTITIONS
CountryCounter chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client 2

GROUP CONSUMER-ID HOST CLIENT-ID #PARTITIONS
OrderCounter client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2 2

--reset-offsets

Reset offsets of consumer group. Supports one consumer group at the time, and instances should be inactive.

Has 2 execution options: --dry-run (the default) to plan which offsets to reset, and --execute to update the offsets. Additionally, the --export option is used to export the results to a CSV format.

You must choose one of the following reset specifications: --to-datetime, --by-duration, --to-earliest, --to-latest, --shift-by, --from-file, --to-current, --to-offset.

To define the scope use --all-topics or --topic. One scope must be specified unless you use '--from-file'.

重置消费者组的偏移量。如果执行消费者组,一次只能指定一个消费组(需要提前关闭相关的消费者和生产者)。有两个执行参数:​​--dry-run​​(默认值)用于打印计划要重置的偏移量,以及 ​​--execute​​ 以更新偏移量。此外,​​--export​​ 选项用于将结果导出为 CSV 格式。 必须选择以下重置类型之一(关于这些重置类型的更多参考请查看 ​​官方文档​​):​​--to-datetime​​, ​​--by-duration​​, ​​--to-earliest​​, ​​--to-latest​​, ​​--shift-by​​, ​​--from-file​​, ​​--to-current​​, ​​--to-offset​​。

例如(以下所有命令均使用 ​​--dry-run​​ 参数打印执行计划,如果执行计划符合你的期望,请把 ​​--dry-run​​ 替换为 ​​--execute​​ 以真正更新偏移量):

  • 重置指定消费组的所有Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --group CountryCounter --dry-run --all-topics

GROUP TOPIC PARTITION NEW-OFFSET
CountryCounter user_card 1 0
CountryCounter user_card 0 521
CountryCounter user_card 2 0
CountryCounter t1 0 0
  • 重置指定消费组的指定Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --group CountryCounter --dry-run --topic t1


GROUP TOPIC PARTITION NEW-OFFSET
CountryCounter t1 0 0
  • 重置所有消费组的所有Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --all-groups --dry-run --all-topics

GROUP TOPIC PARTITION NEW-OFFSET
OrderCounter t2 2 0
OrderCounter t1 0 0
OrderCounter t2 1 0
OrderCounter t2 0 0
CountryCounter user_card 1 0
CountryCounter user_card 0 521
CountryCounter user_card 2 0
CountryCounter t1 0 0
  • 重置所有消费组中指定Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --all-groups --dry-run --topic t1

GROUP TOPIC PARTITION NEW-OFFSET
OrderCounter t1 0 0
CountryCounter t1 0 0

--shift-by <Long: number-of-offsets>

Reset offsets shifting current offset by 'n', where 'n' can be positive or negative.

--state [String]

When specified with '--describe', includes the state of the group. Example: --bootstrap-server localhost:9092 --describe --group group1 --state

和 ​​--describe​​ 配合使用,列出消费者组的状态。例如:

  • 列出指定消费者组的状态
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe --state

GROUP COORDINATOR (ID) ASSIGNMENT-STRATEGY STATE #MEMBERS
CountryCounter 192.168.31.253:9092 (0) range Stable 1
  • 列出所有消费者组的状态
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe --state

GROUP COORDINATOR (ID) ASSIGNMENT-STRATEGY STATE #MEMBERS
CountryCounter 192.168.31.253:9092 (0) range Stable 1

GROUP COORDINATOR (ID) ASSIGNMENT-STRATEGY STATE #MEMBERS
OrderCounter 192.168.31.253:9092 (0) range Stable 1

--timeout <Long: timeout (ms)>

The timeout that can be set for some use cases. For example, it can be used when describing the group to specify the maximum amount of time in milliseconds to wait before the group stabilizes (when the group is just created, or is going through some changes). (default: 5000)

可以为某些用例设置的超时。例如,在显示消费者组的详情时,可以使用它来指定在组稳定之前等待的最长时间(以毫秒为单位)(当组刚刚创建或正在经历一些更改时),默认值:5000

--topic

The topic whose consumer group information should be deleted or topic whose should be included in the reset offset process. In ​​reset-offsets​​ case, partitions can be specified using this format: ​​topic1:0,1,2​​, where 0,1,2 are the partition to be included in the process. Reset-offsets also supports multiple topic inputs.

配合其他命令指定主题名

--verbose

Provide additional information, if any, when describing the group. This option may be used with '--offsets'/'--members'/'--state' and '--bootstrap-server' options only.

Example: --bootstrap-server localhost:9092 --describe --group group1 --members --verbose

在描述组时提供其他信息(如果有的话)。此选项只能与 ​​--offsets​​ ​​--members​​ ​​--state​​ ​​--bootstrap-server​​ 选项一起使用。

--version

Display Kafka version.

打印Kafka版本号

标签:group,--,chenjing,kafka,使用手册,groups,consumer
From: https://blog.51cto.com/u_15413440/5846810

相关文章

  • Kafka RecordAccumulator 三 高并发写入数据
    KafkaRecordAccumulator三高并发写入数据首先我们客户端会通过多线程的方式来发送消息(一般业务需求可能会通过业务系统或者大数据流计算系统如SparkStreaming或者Fl......
  • 一个kafka的bug:StringDeserializer could not be found ,kafka 版 2.6.6
    近期用了个新版本的spring-boot:所以kafka也上到了2.6.6,于是乎遇到了题目上的问题,全网大部分的解决方案见下链接:​​https://www.it610.com/article/129413478502689177......
  • 快速掌握kafka原理解析
    ​简介​Kafka是最初由Linkedin公司开发,是一个分布式、支持分区的(partition)、多副本的(replica),基于zookeeper协调的分布式消息系统,它的最大的特性就是可以实时的处理大量数......
  • mysql-canal-kafka-kettle 数据实时同步链部署bug 填坑过程
     1,因为mysql版本从5.7提高到8.0 ,需要更改用户配置。createuser'canal'@'%'identifiedby'canal';grantselect,replicationslave,replicationclienton......
  • Kafka概述
    1Kafka是什么在流式计算中,Kafka一般用来缓存数据,Storm通过消费Kafka的数据进行计算。1)ApacheKafka是一个开源消息系统,由Scala写成。是由Apache软件基金会开发的一个开源消......
  • Kafka工作流程分析
    Kafka工作流程分析1Kafka生产过程分析1.1写入方式producer采用推(push)模式将消息发布到broker,每条消息都被追加(append)到分区(patition)中,属于顺序写磁盘(顺序写磁盘效率比随机......
  • 【Kafka(二)】日志及索引文件
    每一个分区一个文件夹,一个分区对应多个文件。当满足一定条件后,会生成新的文件。每一个文件叫做一个日志段,每一个日志段会关联两个索引文件,一个是偏移量索引另一个是时间戳索......
  • GVM使用手册
    https://IP账号:admin密码:ymslx-2022                           ......
  • 阿里云kafka使用springboot单个项目中同时消费不同topic
    本来是个简单的问题,但是复杂了。两个topic消费方式不一样,一个使用过的是默认方式,不指定partition,另外一个,指定了特殊的partition。报错:11:10:32.888[org.springframework.......
  • 【Azure 事件中心】使用Apache Flink 连接 Event Hubs 出错 Kafka error: No resolvab
    问题描述参考Github上EventHub的示例代码(UsingApacheFlinkwithEventHubsforApacheKafkaEcosystems : https://github.com/Azure/azure-event-hubs-for-kafka......