1、kafka的send 默认发送方式应该是同步,而非异步
public ApacheKafkaClient(String kafkaServers, boolean sync) throws Exception {
super(kafkaServers, sync);
}
查看父类VersionKafkaClient
2、kafka调用send方法有3种方式
//单条发送
public void send(String topic, String message) throws Exception {
if (topic != null && message != null) {
ProducerRecord<String, String> record = new ProducerRecord(topic, message);
if (this.sync) {
this.producer.send(record).get();
} else {
this.producer.send(record);
}
}
}
//批量发送
public void send(String topic, Collection<String> messages) throws Exception {
Iterator var3 = messages.iterator();
while(var3.hasNext()) {
String message = (String)var3.next();