首页 » SEO优化 » phpkafkatopic位移技巧_Kafka的内部topic__consumer_offsets 消费位移量主题

phpkafkatopic位移技巧_Kafka的内部topic__consumer_offsets 消费位移量主题

访客 2024-12-10 0

扫一扫用手机浏览

文章目录 [+]

默认情形下__consumer_offsets有50个分区。

下面是在windows平台上进行演示的,Linux 平台的命令基本同等,只有命令行路径(bin\windows)以及后缀(.bat)有差异。

phpkafkatopic位移技巧_Kafka的内部topic__consumer_offsets 消费位移量主题

一、查看__consumer_offsets topic主题和分区

运行如下命令,可以看到__consumer_offsets topic,从名称上来推测,这个topic是和consumer的位移干系的。

phpkafkatopic位移技巧_Kafka的内部topic__consumer_offsets 消费位移量主题
(图片来自网络侵删)

bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092

进一步查看topic详细信息

bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092

可以看到__consumer_offsets有50个分区。

__consumer_offest不受server.properties中num.partitions和default.replication.factor参数的制约。
相反地,它的分区数和备份因子分别由offsets.topic.num.partitions和offsets.topic.replication.factor参数决定。
这两个参数的默认值分别是50和1,表示该topic有50个分区,副本因子是1。

consumers 将末了利用的位移量(或偏移量 offset id)存储在基于consumer group id的kafka topic:__consumer_offsets中。
这样,不同的consumers(显然具有不同的consumer id)能够在上一次消费的之后,处理下一条,并避免重复的处理。

二、如何读取__consumer_offsets topic中的?

针对Kafka 2.x版本,可以利用如下命令从__consumer_offsets topic中读取消息:

kafka-console-consumer --bootstrap-server localhost:9092 --topic __consumer_offsets --formatter "kafka.coordinator.group.GroupMetadataManager$OffsetsMessageFormatter"

下面是输出结果:

可以看到__consumer_offsets topic 中的每一日志项的格式都是:

[Group, Topic, Partition]::[OffsetMetadata[Offset, Metadata], CommitTime, ExpirationTime]

个中test-consumer-group (Group)是在consumer.properties 配置的consumer group id:

三、kafka-consumer-groups.sh(.bat)命令

kafka-consumer-groups.sh命令可以查看consumer信息。

1. 查看consumer group列表,利用--list参数

bin\windows\kafka-consumer-groups.bat --list --bootstrap-server localhost:9092

2. 查看特定consumer group 详情,利用--group与--describe参数

bin\windows\kafka-consumer-groups.bat --bootstrap-server localhost:9092 --group console-consumer-43322 --describe

个中,current-offset 和 log-end-offset还有 lag ,分别为当前位移量,结束的位移量,掉队的位移量。

相关文章

php署理源api技巧_国外API代理理解下

API接口日常生活中,许多程序员为重复利用代码会将代码打包成组件模块形式进行调用,调用的办法便是API接口。API代理API代理是...

SEO优化 2024-12-13 阅读0 评论0