Kafka - 消息排序保证
Kafka - Message Ordering 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.
另一个
- (config param) max.in.flight.requests.per.connection - The maximum number of
unacknowledged requests the client will send on a single connection
before blocking. Note that if this setting is set to be greater than
1 and there are failed sends, there is a risk of message re-ordering
due to retries (i.e., if retries are enabled).
问题是,如果像 #2 那样发送失败,订单是否仍会保留到特定分区?如果一条消息存在潜在问题,每个分区将丢弃以下所有消息 "to retain the order" 或将发送 "correct" 条消息并将失败的消息通知应用程序 ?
"will the order still be retained to a particular partition if there are failed sends like mentioned #2?"
正如您复制的文档部分所写,存在更改顺序的风险。
想象一下,您有一个主题,例如一个分区。您将 retries
设置为 100,将 max.in.flight.requests.per.connection
设置为大于 1 的 5。请注意,只有将 acks
设置为 1 或“全部”时重试才有意义。
如果您计划按 K1、K2、K3、K4、K5 的顺序生成以下消息,并且您的制作人需要一些时间才能完成
- 实际创建批处理
- 向经纪人提出请求并
- 等待经纪人的确认
您最多可以并行处理 5 个请求(基于 max.in.flight.request.per.connection
的设置)。现在,生成“K3”出现了一些问题,它进入了重试循环,可以生成消息 K4 和 K5,因为请求已经在进行中。
您的主题将按以下顺序包含消息:K1、K2、K4、K5、K3。
如果您在 Kafka Producer 中启用 idempotency,排序仍将得到保证,如 Ordering guarantees when using idempotent Kafka Producer
中所述
我遇到了两个关于订购的短语,
- 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.
另一个
- (config param) max.in.flight.requests.per.connection - The maximum number of unacknowledged requests the client will send on a single connection before blocking. Note that if this setting is set to be greater than 1 and there are failed sends, there is a risk of message re-ordering due to retries (i.e., if retries are enabled).
问题是,如果像 #2 那样发送失败,订单是否仍会保留到特定分区?如果一条消息存在潜在问题,每个分区将丢弃以下所有消息 "to retain the order" 或将发送 "correct" 条消息并将失败的消息通知应用程序 ?
"will the order still be retained to a particular partition if there are failed sends like mentioned #2?"
正如您复制的文档部分所写,存在更改顺序的风险。
想象一下,您有一个主题,例如一个分区。您将 retries
设置为 100,将 max.in.flight.requests.per.connection
设置为大于 1 的 5。请注意,只有将 acks
设置为 1 或“全部”时重试才有意义。
如果您计划按 K1、K2、K3、K4、K5 的顺序生成以下消息,并且您的制作人需要一些时间才能完成
- 实际创建批处理
- 向经纪人提出请求并
- 等待经纪人的确认
您最多可以并行处理 5 个请求(基于 max.in.flight.request.per.connection
的设置)。现在,生成“K3”出现了一些问题,它进入了重试循环,可以生成消息 K4 和 K5,因为请求已经在进行中。
您的主题将按以下顺序包含消息:K1、K2、K4、K5、K3。
如果您在 Kafka Producer 中启用 idempotency,排序仍将得到保证,如 Ordering guarantees when using idempotent Kafka Producer
中所述