使用Scala编写flink读取kafka数据代码并输出
时间: 2023-03-26 15:03:58 浏览: 175
flink 读取 kafka (DataStream API scala 源码)
可以回答这个问题,以下是Scala编写flink读取kafka数据代码并输出的示例:
```scala
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
val env = StreamExecutionEnvironment.getExecutionEnvironment
val properties = new Properties()
properties.setProperty("bootstrap.servers", "localhost:9092")
properties.setProperty("group.id", "test")
val stream = env.addSource(new FlinkKafkaConsumer[String]("topic", new SimpleStringSchema(), properties))
stream.print()
env.execute("Kafka Flink Example")
```
阅读全文