1 回答
TA贡献1155条经验 获得超0个赞
问题解决了。首先,我用这个命令填满了 Kafka 主题:
/home/kafka_2.11-2.0.0/bin/kafka-console-producer.sh --broker-list 10.32.0.2:9092,10.32.0.3:9092,10.32.0.4:9092 --topic flinkTopic < transactions2.csv
然后,使用此代码,我可以打印 Kafka 主题:
final StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
Properties prop = new Properties();
prop.setProperty("bootstrap.servers",
"10.32.0.2:9092,10.32.0.3:9092,10.32.0.4:9092");
prop.setProperty("group.id", "test");
FlinkKafkaConsumer<String> myConsumer= new FlinkKafkaConsumer<>
("flinkTopic", new SimpleStringSchema(),prop);
myConsumer.setStartFromEarliest();
DataStream<String> stream = env.addSource(myConsumer);
stream.print();
env.execute("Flink Streaming Java API Skeleton");
我希望它对其他人有用。
添加回答
举报