Kafka使用的一些tips小结


在使用Kafka的过程中,最麻烦的地方莫过于Consumer了,如果用High Level API的话,对partition、offset等都无法进行控制;如果用Low Level API的话,又过于复杂,头疼……

这里记录一下在测试过程中(主要针对Consumer的offset)碰到的工具以及使用方法:

利用Kafka自身提供的系统工具

https://cwiki.apache.org/confluence/display/KAFKA/System+Tools

源码地址

https://github.com/apache/kafka/tree/0.8/core/src/main/scala/kafka/tools


Consumer的offset检查(根据group名)
> bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group consumer_group_name
获取某一topic的offset
> bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -1

> bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -2
查看ZooKeeper中的offset情况
> bin/kafka-run-class.sh kafka.tools.ExportZkOffsets --zkconnect localhost:2181 --output-file abc.txt
重放某一topic的内容至另一topic
> bin/kafka-run-class.sh kafka.tools.ReplayLogProducer --broker-list localhost:9092 --zookeeper localhost:2181 --inputtopic test --outputtopic new_test
在控制台打印已消费的messages
> bin/kafka-run-class.sh kafka.tools.SimpleConsumerShell --broker-list localhost:9092 --topic test
在控制台给对应的topic生成messages
> bin/kafka-run-class.sh kafka.producer.ConsoleProducer --broker-list localhost:9092 --topic test
在控制台打印[已]消费的messages
> bin/kafka-run-class.sh kafka.consumer.ConsoleConsumer --zookeeper localhost:2181 --topic test

> bin/kafka-run-class.sh kafka.consumer.ConsoleConsumer --zookeeper localhost:2181 --topic test --from-beginning
查看ZooKeeper上有哪些topic以及topic的详细信息
> bin/kafka-run-class.sh kafka.admin.TopicCommand --zookeeper localhost:2181 --list

> bin/kafka-run-class.sh kafka.admin.TopicCommand --zookeeper localhost:2181 --describe --topic test
参考链接:

 

Kafka的offset监控

因为KafkaOffsetMonitor中有些资源文件(css,js)是访问外网的,特别是有访问google资源,经常不能访问o(╯□╰)o

 

Kafka的可靠性
, ,

《 “Kafka使用的一些tips小结” 》 有 3 条评论

  1. Kafka是如何实现几十万的高并发写入
    https://binchencoder.github.io/2019/08/28/kafka是如何实现几十万的高并发写入/
    `
    使用MQ(消息队列)来设计系统带来的好处:业务解耦、流量削峰、灵活扩展

    Kafka就是基于页缓存技术 + 磁盘顺序写 技术实现了写入数据的超高性能。

    要保证每秒写入几万甚至几十万条数据的核心点,就是尽最大可能提升每条数据写入的性能,这样就可以在单位时间内写入更多的数据量,提升吞吐量。

    Kafka 在读数据的时候引入了零拷贝技术,直接让操作系统的cache中的数据发送到网卡后传出给下游的消费者,中间跳过了两次拷贝数据的步骤,Socket缓存中仅仅会拷贝一个描述符过去,不会拷贝数据到Socket缓存。
    `
    https://binchencoder.github.io/2019/08/27/%E5%88%9D%E8%AF%86kafka/
    http://kafka.apachecn.org/documentation.html#maximizingefficiency
    http://kafka.apachecn.org/documentation.html#persistence

回复 hi 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注