我正在尝试向Kafka主题推送消息。该主题是在AWS EC2实例上创建的。当我从计算机(本地主机)将消息推送到主题时,什么也没发生。但是,当我尝试从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
下面是我的生产者Java代码
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();
}