kafka使用high api怎样确保不丢失消息,不重复发送,消息只读取一次( 二 )


■网友
最近正好在看kafka权威指南(Kafka: The De?nitive Guide) 介绍了利用数据库事务的方式保证commit offset提交正确性的方式。当然这样的话offset就不会保存在kafka中。可能对你有所启发
:在Consuming Records withSpeci?cOffsets这一章
But what if we wrote both the record and the offset to the database, in one transac‐
tion? Then we’ll know that either we are done with the record and the offset is com‐
mitted or we are not and the record will be reprocessed...........................................
我刚看完了这一章最后一段话


There are many different ways to implement exactly-once semantics by storing offsets
and data in an external store, but all of them will need to use the ConsumerRebalance
Listener and seek() to make sure offsets are stored in time and that the consumer
starts reading messages from the correct location.

如果想实现仅仅一次的语义的话方法还是有的,但是明显如果使用kafka内部的offset提交机制的话并不能实现。书里面也说过类似的话:


As long as the records are written to a database and the offsets
to Kafka, this is impossible.
kafka最初是领英公司为解决需求的产品
权威指南的作者也是kafka的设计者之一我觉得权威性还是可信的

■网友
【kafka使用high api怎样确保不丢失消息,不重复发送,消息只读取一次】 具体的可以看看为这篇文章:Kafka消息投递语义-消息不丢失,不重复,不丢不重

■网友
针对消息丢失,撇开api及业务的保证,kafka其本身也不是确保消息完全的不丢,如,副本未同步完全,leader节点出现故障;kafka消息刷磁盘机制。
■网友
高级api本身就能满足不丢消息不重复读消息,找个样例跑一下就行了。只不过实现的机制非常傻,可靠性极差。说一下,kafka本身就是一个非常傻的日志收集系统。注意,是日志收集系统不是消息系统!负载均衡以及消息可靠性顺序性保证都极差,基本都要靠使用者自己操心。在我看来,kafka只是分布式的把发送端提交的信息记录在服务端的文件里,仅此而已。


推荐阅读