好的,我知道您只能获得每个分区的订单保证。
只是随机的想法/问题。
假设分区策略是正确的,并且将消息正确地分组到适当的分区(甚至说我们正在使用1个分区)
我想生产应用程序必须将每个消息一一发送到kafka,并确保在发送下一消息之前已确认每个消息?
最佳答案
是的,您是正确的,生产应用程序发送消息的顺序决定了它们存储在分区中的顺序。
Messages sent by a producer to a particular topic partition will be appended in the order they are sent. That is, if a message M1 is sent by the same producer as a message M2, and M1 is sent first, then M1 will have a lower offset than M2 and appear earlier in the log. http://kafka.apache.org/documentation.html#intro_guarantees
但是,如果同时有多条消息正在发送,则不确定如何确定顺序。
您可能还需要考虑生产者的
acks
配置。在某些失败情况下,如果发布M1并新的领导者收到M2之后领导者掉线,消息可能会丢失。在这种情况下,您将不会出现乱序情况,而是会丢失一条消息,因此它与您的原始问题略有正交,但是如果消息保证和顺序对您的应用程序至关重要,则需要考虑一些问题。http://kafka.apache.org/documentation.html#producerconfigs
总的来说,设计一个顺序差异不那么重要的系统可以真正简化事情。
关于apache-kafka - 如何保证Kafka分区中的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39643210/