1.建立一个测试主题:
[[email protected]nn bin]#./kafka-topics.sh --zookeeper snn:2181 --topic offset-test --partitions 2 --replication-factor 2 –create
检查主题的设置情况:
[[email protected] bin]#./kafka-topics.sh --zookeeper snn:2181 --topic offset-test –describe
2.向主题中写入数据
[[email protected] bin]# ./kafka-console-producer.sh --broker-list snn:6667 --topic offset-test
3.消费主题
[[email protected] bin]# ./kafka-console-consumer.sh --bootstrap-server snn:6667 --group offsettest --topic offset-test –from-beginning
4.查看消费者消费偏移量
[[email protected] bin]#./kafka-consumer-groups.sh --bootstrap-server snn:6667 --group offsettest –describe
5.设置为最初偏移量:
[[email protected] bin]#./kafka-consumer-groups.sh --bootstrap-server snn:6667 --group offsettest --topic offset-test --reset-offsets --to-earliest –execute
重新读取数据:
6.设置任意偏移量:
[[email protected] bin]# ./kafka-consumer-groups.sh --bootstrap-server snn:6667 --group offsettest --topic offset-test --reset-offsets --to-offset 3 –execute
7.设置最近偏移量
[[email protected] bin]# ./kafka-consumer-groups.sh --bootstrap-server snn:6667 --group offsettest --topic offset-test --reset-offsets --to-latest --execute