首先需要安装好netcat,在centos中没有 -k 参数的命令。
第一步:完成spark的scala程序
package com.lxb.sparkStreaming
import org.apache.spark.streaming.dstream.{DStream, ReceiverInputDStream}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.streaming.{Seconds, StreamingContext}
object SparkStreaming{
def main(args: Array[String]): Unit = {
val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("SparkStreaming")
//def this(sparkContext : org.apache.spark.SparkContext,
// batchDuration : org.apache.spark.streaming.Duration)
// 第一个参数是:SparkConf,第二个参数是:计算周期
val streamingContext: StreamingContext = new StreamingContext(conf, Seconds(5))
// 获取数据
val socketLine: ReceiverInputDStream[String] = streamingContext.socketTextStream("node11", 9999)
// 将获取的数据进行扁平化处理
val wordDSStream: DStream[String] = socketLine.fl