|
|
|
@ -56,9 +56,19 @@ public class KafkaProductorTest {
|
|
|
|
|
, 0, "HuangHai_" + i, "{\"id\":" + i + ",\"name\"=\"HuangHai_" + i + "\"}");
|
|
|
|
|
|
|
|
|
|
//等待消息发送成功的同步阻塞方法
|
|
|
|
|
RecordMetadata metadata = producer.send(producerRecord).get();
|
|
|
|
|
System.out.println("同步方式发送消息结果:" + "topic-" + metadata.topic() + "|partition-"
|
|
|
|
|
+ metadata.partition() + "|offset-" + metadata.offset() + "|" + i);
|
|
|
|
|
//RecordMetadata metadata = producer.send(producerRecord).get();
|
|
|
|
|
//System.out.println("同步方式发送消息结果:" + "topic-" + metadata.topic() + "|partition-"
|
|
|
|
|
//+ metadata.partition() + "|offset-" + metadata.offset() + "|" + i);
|
|
|
|
|
|
|
|
|
|
// 异步发送消息
|
|
|
|
|
producer.send(producerRecord, (metadata, exception) -> {
|
|
|
|
|
if (exception != null) {
|
|
|
|
|
System.err.println("异步发送消息失败:" + exception.getMessage());
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("异步方式发送消息结果:" + "topic-" + metadata.topic() + "|partition-"
|
|
|
|
|
+ metadata.partition() + "|offset-" + metadata.offset());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
producer.close();
|
|
|
|
|
}
|
|
|
|
|