5 Kafka Streams exactly once semantic

自Kafka 0.11版本起,引入了Exactly Once语义,确保消息能被精确地消费和生产一次。通过idempotent特性,即使生产者重试发送相同消息,Kafka也只会保留一份副本。此特性虽会轻微影响性能,但提供了更强大的数据一致性保障。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

About Exactly Once Semantic

Since Kafka 0.11 version Kafka support Exactly Once Semantic, which means, that Kafka can give you the grarantee that each messege can be exactly once consumed/produced to/from Kafka.

There are a lot of engineering details, which I wouldn't explain here... In this section I want to keep it simple.

Since 0.11 version there is a new implementation for this Exactly Once Semantic, which is idempotent !

It means if a producer send the same messeage twice or retries, Kafka will make sure to only keep one copy of it !

For example in a typically process for Producer:

  • producer send a messeage to Kafka
  • Kafka receive the messege
  • and send back a Acknowledgement to Producer
  • Producer commit Offset (done)

in step two, if Kafka just receive the messege and then lost the network connection, Kafka will not be able to send back the Acknowledgement. In this case Producer will send the messege again by retry. Then will Kafka receive the this messege at this moment twoice. But with Idempotent it will only keep one copy of them.

How to do exactly once in Kafka Streams

Very simple, only add one more line of code in configuration property file:

PS: with this feature it could slow down Kafka a little bit.. but it's fine :-)

You can also fine tune the setting using commit.interval.ms

 

转载于:https://www.cnblogs.com/crazy-chinese/p/10498658.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值