|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 2022-04-09 14:10  yanqi_vip  阅读(33)  评论(0)    收藏  举报

导航