研一课程《大数据》的第三次作业。
解:
开启一个console,打开netcat工具作为被监控的广播站。nc -l -p 10080
然后如下:
package com.nju.se.master.grade17.example.ToxicGasListenerInJava;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.spark.*;
import org.apache.spark.api.java.function.*;
import org.apache.spark.streaming.*;
import org.apache.spark.streaming.api.java.*;
public class SparkStream {
public static void main(String[] args) {
// Create a local StreamingContext with two working thread and batch
// interval of 1 second
SparkConf conf = new SparkConf().setMaster("local[2]").setAppName("LocalGasListener");
JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(5));
//System.out.println(jssc);
JavaDStream<