flink的Kafka数据源代码样例

 1 val properties = new Properties()
 2 properties.setProperty("bootstrap.servers", "localhost:9092")
 3 properties.setProperty("group.id", "consumer-group")
 4 properties.setProperty("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
 5 properties.setProperty("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
 6 properties.setProperty("auto.offset.reset", "latest")
 7 val env = StreamExecutionEnvironment.getExecutionEnvironment
 8 env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
 9 env.setParallelism(1)
10 val stream = env
11   // source为来自Kafka的数据,这里我们实例化一个消费者,topic为hotitems
12   .addSource(new FlinkKafkaConsumer[String]("hotitems", new SimpleStringSchema(), properties))

 

posted @ 2019-11-04 20:21  啊啊啊啊鹏  阅读(512)  评论(0编辑  收藏  举报
1 2