Why async producer is not waiting for either linger.ms or batch.size to be full when i set them a custom value with autoFlush is set to false?

橙三吉。 提交于 2021-01-29 10:22:57

问题


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

  1. How the messages are being published instead of waiting for either linger.ms or batch.size before producing the message?
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!