Apache Kafka:Java Producer 的可重用性

Apache Kafka:Java Producer 的可重用性

问题描述:

有人知道吗

kafka.javaapi.producer.Producer

kafka.javaapi.producer.Producer

可以在多个方法调用之间重用(例如多个 send(...))还是每次都应该关闭?

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

是的,它肯定可以重复使用.Producer 创建操作非常缓慢,因为它需要与所有分区(可能还有 zookeeper)建立连接.因此,应该尽可能重用生产者.

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.