Kafka guarantees message order

Order guarantee
Kafka can guarantee that the messages in the same partition are in order. In other words, if the producer sends messages in a certain order, the broker will write them to the partition in this order, and the consumer will read them in the same order.

1. Single partition
2. If you set retries to a non-zero integer, you must set max.in.flight.requests.per.connection = 1 (the maximum number of unconfirmed requests sent by the client on a single connection).
If you set retries to Is a non-zero integer, and at the same time, set max.in.flight.requests.per.connection to a number greater than 1, then, if the writing of the first batch of messages fails and the writing of the second batch is successful, the broker Will retry writing the first batch. If the first batch is also written successfully at this time, then the order of the two batches is reversed.

Generally speaking, if some scenarios require messages to be in order, then whether the message is successfully written is also very important, so it is not recommended to set retries to 0. You can set max.in.flight.requests.per.connection to 1, so that when the producer tries to send the first batch of messages, no other messages will be sent to the broker. However, this will seriously affect the throughput of the producer, so this can only be done if there are strict requirements on the order of the messages.

Guess you like

Origin blog.csdn.net/yangshengwei230612/article/details/114604991