apache-kafka - Kafka ordering with multiple producers on same topic and parititon
问题描述
Let's say I have two producers (ProducerA and ProducerB) writing to the same topic with a single partition. Each producer is writing it's own unique events serially. So if ProducerA fired 3 events and then ProducerB fired 3 events, my understanding is that Kafka cannot guarantee the order across the producer's events like this:
- ProducerA_event_1
- ProducerA_event_2
- ProducerA_event_3
- ProducerB_event_1
- ProducerB_event_2
- ProducerB_event_3
due to acking, retrying, etc.
However will individual producer's events still be in order? For example:
- ProducerA_event_1
- ProducerB_event_2
- ProducerB_event_1
- ProducerA_event_2
- ProducerA_event_3
- ProducerB_event_3
This is of course a simplified version of what I am doing, but I just want to guarantee that if I am reading from a topic for a specific producer's events, then those events will be in order even if other producer's events interleave them.
解决方案
有一篇关于 medium的好文章指出,即使对于同一个生产者,Kafka 也不总是保证消息的顺序。这一切都取决于 Kafka 配置。特别是,max.in.flight.requests.per.connection
必须设置为1
。原因是如果有多个请求(例如 2 个)在运行,而第一个请求失败,则第二个请求会更早地附加到日志中,从而破坏排序。
推荐阅读
- ajax - CSRF 令牌丢失或无效。-> 第一种形式使其他 CSRF 令牌工作失败
- java - 如何使用 GNU Prolog for Java 运行包含列表作为参数的谓词?
- actionscript-3 - 如何修复 ActionScript3.0 Adobe Animate 中的“TypeError: Error #1009”错误
- javascript - 如何绘制具有 n 边的任意不规则多边形?
- r - flextable:如何仅将组标题显示为值而不是变量名:值
- java - 有没有办法在新的导航组件上按下后恢复 recyclerview 上的状态
- javascript - 将谷歌街景与地点搜索相结合
- matlab - 在 simulink 库浏览器中查找并显示所有现有模块
- javascript - 围绕对象opencv.js的边界矩形在控制台中抛出错误
- git - Git 推送到远程而不拉取并防止远程文件被删除