1. 测试代码
package spark.examples.streaming
import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext._
import org.apache.spark.streaming._
object NetCatStreamingWordCountDelay {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("NetCatStreamingWordCountDelay")
conf.setMaster("local[3]")
//Receive data every second
val ssc = new StreamingContext(conf, Seconds(1))
val lines = ssc.socketTextStream("192.168.26.140", 9999)
//Each processing should take about 4 seconds.
lines.foreachRDD(rdd => {
println("This is the output even if rdd is empty")
Thread.sleep(4 * 1000)
})
ssc.start()
ssc.awaitTermination()
}
}
上面的测试代码:
1. 时间间隔设置为1秒,也就是说,每隔1秒钟,Spark Streaming将创建一个RDD
2.