我想给Kafka的主题传递一个信息。主题是在aws ec2示例上创建的。当我从我的机器(localhost)将消息推送到主题时,什么都没有发生。但是,当我试图从ec2示例手动推送它时,它工作正常。我还要确保我的示例允许所有的入/出边界流量。
server.properties文件
zookeeper.connect=localhost:2181
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=1000000
# public IP for the instance
advertised.listeners=PLAINTEXT://18.222.151.131:9092
# private IP for the instance
listeners=PLAINTEXT://172.31.43.18:9092
下面是我的producerjava代码
public static void run() throws InterruptedException {
Properties properties = new Properties();
properties.put("bootstrap.servers", "18.222.151.131:9092");
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer kafkaProducer = new KafkaProducer(properties);
kafkaProducer.send(new ProducerRecord(topic, "Hello AWS"));
producer.close();
}
暂无答案!
目前还没有任何答案,快来回答吧!