如何在JAVA中将RDD转换为DStream?

时间:2016-03-18 14:17:42

标签: apache-spark

我已经检查了http://apache-spark-user-list.1001560.n3.nabble.com/RDD-to-DStream-td11145.html,并想在JAVA中做同样的事情。这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:2)

根据javadoc你可以这样做。

//Create list
List<SomePojo> somePojoList = ...;             

//Create rdd
JavaRDD<SomePojo> rdd = streamingContext.sparkContext().parallelize( somePojoList);
        java.util.Queue<JavaRDD<SomePojo>> queue = new LinkedList<JavaRDD<SomePojo>>();
        queue.add( rdd );
        JavaDStream<SomePojo> machineDataDstream = streamingContext.queueStream( queue );