Apache Kafka: Java Producer reusability

2019-09-10 03:04发布

问题:

Does anybody know if

kafka.javaapi.producer.Producer

can be reused among several method invocations (e.g. several send(...)) or it should be closed each time?

回答1:

Yes, it can surely be reused. Producer creation is pretty slow operation because it requires establishing connection to all partitions (and probably zookeeper). So, Producers should be reused when possible.