kafka学习总结

 kafka启动流程:

创建topic kafka-topics.sh --zookeeper master:2181 --create --partitions 2 --replication-factor 3 --topic bd14first

查看topic: kafka-topics.sh --zookeeper master:2181 --list

 查看刚刚创建的partition的信息

kafka-topics.sh --zookeeper master:2181 --describe --topic bd14first

offset:

kafka-console-consumer.sh --bootstrap-server master:9092,master:9093 --topic bd14first --offset earliest --partition 0

执行delete之后使用list指令,查看的topic的状态为

marked for deletion,此时topic并未被真正的删除
[root@slaver1 ~]# kafka-topics.sh --zookeeper master:2181 --list
__consumer_offsets
bd14first - marked for deletion

 删除topic有两种方式,一种是在配置文件中配置delete.topic.enable为true

另一种是在zookeeper的客户端中删除对应topic下的partitions:

[zk: localhost:2181(CONNECTED) 11] rmr /brokers/topics/bd14first/partitions

kafka的数据丢失:kafka的元数据维护是由kafka自身类完成的,数据丢失出现在读数据的时候

在从kafka中取出数据的时候,offset会发生变化,取出的数据有可能要进行复杂的计算,计算过程中可能会发生失败的情况

,再启动之后offset已经发生变化,会造成数据丢失;解决办法是把kafka的数据自己维护,但是会比较麻烦

Kafka delivery guarantee

有这么几种可能的delivery guarantee

  • At most once 消息可能会丢,但绝不会重复传输
  • At least one 消息绝不会丢,但可能会重复传输
  • Exactly once 每条消息肯定会被传输一次且仅传输一次,很多时候这是用户所想要的。

原文地址:https://www.cnblogs.com/zuizui1204/p/7808631.html