Apache kafka KafkaProducer.close()和KafkaProducer.flush()之间的差异

Apache kafka KafkaProducer.close()和KafkaProducer.flush()之间的差异,apache-kafka,kafka-producer-api,Apache Kafka,Kafka Producer Api,查看文档,我不确定是否理解使用和之间的区别 这是flush()的文档 以及关闭()的文档: 这是否意味着: 如果我使用close()并且内存缓冲区中有一些记录挂起,那么它们甚至不会被尝试(与flush相比,flush会尝试发送它们) 如果我使用flush(),如果重试次数很大,它可能会阻止“永远”?使用close()时,我有一个上限,表示这将需要多长时间 我想,如果我在1中说得对,acks=0的制作者会得到一条记录的确认,如果该记录“不幸”被放入内存队列,并在调用close()后立即被发布,则该

查看文档,我不确定是否理解使用和之间的区别

这是flush()的文档

以及关闭()的文档:

这是否意味着:

  • 如果我使用close()并且内存缓冲区中有一些记录挂起,那么它们甚至不会被尝试(与flush相比,flush会尝试发送它们)
  • 如果我使用flush(),如果重试次数很大,它可能会阻止“永远”?使用close()时,我有一个上限,表示这将需要多长时间

  • 我想,如果我在1中说得对,acks=0的制作者会得到一条记录的确认,如果该记录“不幸”被放入内存队列,并在调用close()后立即被发布,则该记录甚至可能不会被发布。

    如果您想继续使用制作者并等待消息发送,您可以使用flush-else-close。Close with timeout value将根据配置等待消息发送和ack接收,直到超时值,然后关闭生产者

     * Invoking this method makes all buffered records immediately available to send (even if <code>linger.ms</code> is
     * greater than 0) and blocks on the completion of the requests associated with these records. The post-condition
     * of <code>flush()</code> is that any previously sent record will have completed (e.g. <code>Future.isDone() == true</code>).
     * A request is considered completed when it is successfully acknowledged
     * according to the <code>acks</code> configuration you have specified or else it results in an error.
    
     * This method waits up to <code>timeout</code> for the producer to complete the sending of all incomplete requests.
     * If the producer is unable to complete all requests before the timeout expires, this method will fail
     * any unsent and unacknowledged records immediately.