def main(args: Array[String]): Unit = {
//创建flink执行环境
val env = StreamExecutionEnvironment.getExecutionEnvironment
//设置并行度
env.setParallelism(1)
//从kafka获取数据
val properties = new Properties()
properties.setProperty(“bootstrap.servers”, “hdp111:9092,hdp222:9092,hdp333:9092”)
properties.setProperty(“zookeeper.connect”, “hdp111:2181,hdp222:2181,hdp333:2181”)
properties.setProperty(“group.id”, “consumer-group”)
val dataStream: DataStream[String] = env.addSource(new FlinkKafkaConsumer011[String](“Kafkaflink”,new SimpleStringSchema(),properties))
val value1: DataStream[(String, Int)] = dataStream.map(x=>(“车牌总数”,1)).keyBy(0).timeWindow(Time.seconds(5)).sum(1)
value1.print(“五秒内出现的总次数”)
dataStream.split(x=>{
val str = x.takeRight(1)
val int = str.toInt
if (int % 2 == 0) {
Seq(“edd”)
}else{
Seq(“eved”)
}
}).select(“edd”).print(“偶数车牌”)
dataStream.map((_,1)).keyBy(0).timeWindow(Time.seconds(10)).sum(1).filter(x=>x._2>=2).print(“车牌数量大于2”)
env.execute()
}