看文档,我不确定我是否了解使用close()和flush()之间的区别。
这是flush()的文档
* 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.
还有close()的文档:
* 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.
这是否意味着:
我想如果我对1.正确,那么acks = 0的制作人将获得一条记录的确认,如果记录“不幸”到足以放置在in-中,甚至可能不会尝试发布该记录。内存队列,并在调用close()之后立即进行。
答案 0 :(得分:0)
如果要继续使用生产者并等待发送消息,则可以使用flush else close。使用超时值关闭将等待按照配置发送和确认消息,直到超时值,然后关闭生产者