当前位置:   article > 正文

Kafka服务器命令总结_kafka-console-consumer.sh指定clientid

kafka-console-consumer.sh指定clientid

1. 生产者相关

  1. 发送消息(这里注意不能使用localhost,要使用指定ip)
[root@iZ2zedqr9yeos47fg4uor5Z kafka_2.12-2.8.0]# bin/kafka-console-producer.sh --broker-list 172.24.10.198:9092 --topic test
>a
>b
  • 1
  • 2
  • 3

2. 消费者相关

  1. 消费消息
[root@iZ2zedqr9yeos47fg4uor5Z kafka_2.12-2.8.0]# bin/kafka-console-consumer.sh --bootstrap-server 172.24.10.198:9092 --topic test --from-beginning
a
b
  • 1
  • 2
  • 3
  1. 查看所有的消费者组
[root@iZ2zedqr9yeos47fg4uor5Z kafka_2.12-2.8.0]# ./bin/kafka-consumer-groups.sh --bootstrap-server 172.24.10.198:9092 --list
test-consumer-group
  • 1
  • 2
  1. 查看指定消费者组的消费情况
[root@iZ2zedqr9yeos47fg4uor5Z kafka_2.12-2.8.0]# ./bin/kafka-consumer-groups.sh --bootstrap-server 172.24.10.198:9092 --describe --group test-consumer-group

Consumer group 'test-consumer-group' has no active members.

GROUP               TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID     HOST            CLIENT-ID
test-consumer-group test            0          4611            4611            0               -               -               -
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  1. 重置offset
[root@iZ2zedqr9yeos47fg4uor5Z bin]# ./kafka-consumer-groups.sh --bootstrap-server 172.24.10.198:9092 --group test-consumer-group --reset-offsets --topic test2 --to-offset 100 --execute

GROUP                          TOPIC                          PARTITION  NEW-OFFSET
test-consumer-group            test2                          0          100
  • 1
  • 2
  • 3
  • 4
--to-earliest:   设置到最早位移处,也就是0
--to-latest:     设置到最新处,也就是主题分区HW的位置
--to-offset NUM: 指定具体的位移位置
--shift-by NUM:  基于当前位移向前回退多少
--by-duration:   回退到多长时间
  • 1
  • 2
  • 3
  • 4
  • 5

3. 主题相关

  1. 查看主题
[root@iZ2zedqr9yeos47fg4uor5Z kafka_2.12-2.8.0]# bin/kafka-topics.sh --list --zookeeper localhost:2181
__consumer_offsets
test
zxf
  • 1
  • 2
  • 3
  • 4
  1. 清除主题数据
[root@iZ2zedqr9yeos47fg4uor5Z bin]# ./kafka-topics.sh --delete --zookeeper 172.24.10.198:2181 --topic test
Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
  • 1
  • 2
  • 3
  1. 修改某个主题的过期时间(不需要重启kafka,内存修改,重启kafka后会丢失)
[root@iZ2zedqr9yeos47fg4uor5Z bin]# ./kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name topic_name_xx --alter --add-config retention.ms=1296000000
Warning: --zookeeper is deprecated and will be removed in a future version of Kafka.
Use --bootstrap-server instead to specify a broker to connect to.
Completed updating config for entity: topic 'topic_name_xx'.
  • 1
  • 2
  • 3
  • 4
  1. 查看某个主题的当前过期时间配置
[root@iZ2zedqr9yeos47fg4uor5Z bin]#  ./kafka-topics.sh --zookeeper localhost:2181 --topic topic_name_xx --describe
Topic: topic_name_xx        TopicId: FntNDJn6QdS9XEiA8FDUIw PartitionCount: 1       ReplicationFactor: 1    Configs: retention.ms=1296000000
        Topic: topic_name_xx        Partition: 0    Leader: 0       Replicas: 0     Isr: 0
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/142512
推荐阅读
相关标签
  

闽ICP备14008679号