首先,偏移量管理实例[需要启动代码程序查看]
### --- 查看指定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