问题
I am using spring-kafka 2.2.8 and writing a simple async producer with the below settings:
linger.ms : 300000,
batch.size: 33554431,
max.block.ms: 60000.
Now i'm creating a KafkaTemplate with autoFlush as false by calling the below constructor
public KafkaTemplate(ProducerFactory<K, V> producerFactory, boolean autoFlush)
Now i've a simple test producing 10 message in the span of 10 sec using the above async producer and then stopped my producer using 'Cntrl+C'. Then surprisingly, i got all the 10 messages published onto the topic and i'm sure the size of these 10 messages combined is way less than my batch.size: 33554431
Now i've two questions
- How the messages are being published instead of waiting for either linger.ms or batch.size before producing the message?
- In this scenario, what is the significance of autoFlush= false?
回答1:
If this is a Spring Boot application, Ctrl-C will close the application context and the DefaultKafkaProducerFactory
will close the producer in its destroy()
method (called by the application context during close()
).
You will only lose records if you kill -9
the application.
来源:https://stackoverflow.com/questions/62807232/why-async-producer-is-not-waiting-for-either-linger-ms-or-batch-size-to-be-full