importorg.apache.flink.api.common.functions.FlatMapFunction;importorg.apache.flink.api.java.tuple.Tuple2;importorg.apache.flink.streaming.api.datastream.DataStream;importorg.apache.flink.streaming.api.environment.StreamExecutionEnvironment;importorg.apache.flink.util.Collector;importredis.clients.jedis.Jedis;importredis.clients.jedis.JedisPool;importredis.clients.jedis.JedisPoolConfig;importjava.util.*;publicclassStreamingJob{/**
* Skeleton for a Flink Streaming Job.
*
* <p>For a tutorial how to write a Flink streaming application, check the
* tutorials and examples on the <a href="http://flink.apache.org/docs/stable/">Flink Website</a>.
*
* <p>To package your appliation into a JAR file for execution, run
* 'mvn clean package' on the command line.
*
* <p>If you change the name of the main class (with the public static void main(String[] args))
* method, change the respective entry in the POM.xml file (simply search for 'mainClass').
*/publicstaticvoidmain(String[] args)throwsException{StreamExecutionEnvironment env =StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);//接收消息并将数据转化为流DataStream<String> stream = env.addSource(newMqttConsumer());//通过函数转化流的形式DataStream<Tuple2<String,String>> dataStream = stream.flatMap(newFlatMapFunction<String,Tuple2<String,String>>(){@OverridepublicvoidflatMap(String value,Collector<Tuple2<String,String>> out)throwsException{
out.collect(Tuple2.of(str[0], str[1]));}}).setParallelism(1);//线程并行数量
dataStream.print();
env.execute();}}