|NO.Z.00048|——————————|BigDataEnd|——|Hadoop&kafka.V33|——|kafka.v33|偏移量管理.v02|

一、偏移量管理实例[需要启动代码程序查看]
### --- 查看指定group.id 的消费者消费情况

[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group group
Note: This will not show information about old Zookeeper-based consumers.
~~~输出参数
TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG        CONSUMER-ID                                       HOST                           CLIENT-ID
tp_demo_02                     0          0               0               0          consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
tp_demo_02                     1          0               0               0          consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
tp_demo_02                     2          0               0               0          consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
### --- 如果消费者停止,查看偏移量信息:

[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --group group
Note: This will not show information about old Zookeeper-based consumers.

TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG        CONSUMER-ID                                       HOST                           CLIENT-ID
tp_demo_02                     0          865             881             16         consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
tp_demo_02                     1          892             911             19         consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
tp_demo_02                     2          896             916             20         consumer-1-369336a0-dd00-4a38-86df-284df1f515a6   /192.168.1.108                 consumer-1
### --- 启动生产者:将偏移量设置为最早的:

[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--reset-offsets --group group --to-earliest --topic tp_demo_02
Note: This will not show information about old Zookeeper-based consumers.

TOPIC                          PARTITION  NEW-OFFSET     
tp_demo_02                     2          0              
tp_demo_02                     1          0              
tp_demo_02                     0          0 
### --- 将偏移量设置为最新的:

[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--reset-offsets --group group --to-latest --topic tp_demo_02
Note: This will not show information about old Zookeeper-based consumers.

TOPIC                          PARTITION  NEW-OFFSET     
tp_demo_02                     2          916            
tp_demo_02                     1          911            
tp_demo_02                     0          881 
### --- 分别将指定主题的指定分区的偏移量向前移动10个消息:

[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--reset-offsets --group group --topic tp_demo_02:2 --shift-by -10
Note: This will not show information about old Zookeeper-based consumers.


TOPIC                          PARTITION  NEW-OFFSET     
tp_demo_02                     2          886            
[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--reset-offsets --group group --topic tp_demo_02:1 --shift-by -10
Note: This will not show information about old Zookeeper-based consumers.


TOPIC                          PARTITION  NEW-OFFSET     
tp_demo_02                     1          882            
[root@hadoop ~]# kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--reset-offsets --group group --topic tp_demo_02:0 --shift-by -10
Note: This will not show information about old Zookeeper-based consumers.


TOPIC                          PARTITION  NEW-OFFSET     
tp_demo_02                     0          855 

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(22)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示