前言
版本:本文采用的springboot版本为2.1.3.RELEASE,对应的springkafka也是属于此版本。
起因:在学习springboot对kafka 的操作中,碰到过flush()函数,于是想探究下此函数的功能,就有了本文。
风遁!函数追踪术
新建一个springboot的项目,注入spring-kafka的依赖。打开KafkaTemplate的API搜索可以找到flush()方法,
public void flush() {
Producer producer = this.getTheProducer();
try {
producer.flush();
} finally {
this.closeProducer(producer, this.inTransaction());
}
}
再点击producer.flush()的flush(),发现是个接口类,再找下它的实现类。
public interface Producer<K, V> extends Closeable {
。。。。。
/**接口类Producer
* See {@link KafkaProducer#flush()}
*/
void flush();
。。。。
}
/**Prod