package com.lin.spark import org.apache.spark.sql.SparkSession object StructuredStreaming { def main(args: Array[String]): Unit = { val spark = SparkSession .builder() .appName("StructuredStreaming") .master("local[2]") .getOrCreate() import spark.implicits._ val lines = spark.readStream .format("socket") .option("host","hadoop000") .option("port",9999) .load() val words = lines.as[String].flatMap(_.split(" ")) val wordCounts = words.groupBy("value").count() val query = wordCounts.writeStream .outputMode("complete") .format("console") .start() query.awaitTermination() } }
> nc -lk 9999