Kafka 2.6卡住,Topic not present in metadata
· 阅读需 3 分钟
想自己耍耍Kafka,简单装好后,运行个简单的demo,结果直接卡住不动了,但使用命令行发消息是正常的。我的Kafka版本为2.6,demo代码为:
package top.jlice;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
public class MyProducer {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("bootstrap.servers", "localhost:9092");
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer<String, String> producer = new KafkaProducer<>(properties);
for (int i = 0; i < 10; i++) {
producer.send(new ProducerRecord<String, String>("test", "jlice.top-" + i));
}
producer.close();
}
}