apache-kafka - 卡夫卡排序保证

标签 apache-kafka kafka-producer-api

我正在浏览 kafka 文档并遇到了

Guarantees

At a high-level, Kafka gives the following guarantees:

Messages sent by a producer to a particular topic partition will be appended in the order they are sent. That is, if a record M1 is sent by the same producer as a record M2, and M1 is sent first, then M1 will have a lower offset than M2 and appear earlier in the log. A consumer instance sees records in the order they are stored in the log. For a topic with replication factor N, we will tolerate up to N-1 server failures without losing any records committed to the log.



我有几个问题。
  • 是否总是保证 M1 的偏移量低于 M2 ?如果 M1 晚于 M2 重试怎么办?
  • 我从各种文档中也了解到,订购是没有保障的,消费者必须自己处理。
  • 最佳答案

    即使只有一个分区,一种可能的情况是:

  • 制作人发送 M1
  • 制作人发送 M2
  • M1由于某些失败,在第一次尝试时没有被确认
  • M2已发货
  • M1在随后的尝试中交付。

  • 避免这种情况的一种简单方法是通过生产者配置 max.in.flight.requests.per.connection=1 .

    这当然会影响性能,因此应谨慎使用。

    关于apache-kafka - 卡夫卡排序保证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46127716/

    相关文章:

    java - Springboot - Spring Kafka - 惰性容器工厂初始化

    apache-kafka - IoT - 多个 Kafka 生产者向同一主题发布消息

    java - 获取 kafka-producer 中主题订阅者数量的选项

    java - 卡夫卡流: Invalid topology: StateStore is not added yet

    java - 如何显示在 DStream 中更新的当前累加器值?

    java - KafkaStreams 在读取主题时写入磁盘

    hadoop - Spring Cloud Dataflow-http |卡夫卡和卡夫卡| hdfs-在HDFS中获取原始消息

    java - 如何列出kafka集群的所有生产者?

    java - Producer#initTransactions 不适用于 KafkaContainer

    apache-kafka - 如何检测kafka主题中的重复消息?