SparkStreaming 從Flume Poll資料
1.官網資料
2.需要下載相關依賴到flume的lib中
3.配置flume的配置檔案
#agent1表示代理名稱
agent1.sources=source1
agent1.sinks=sink1
agent1.channels=channel1
#配置source1
agent1.sources.source1.type=spooldir
agent1.sources.source1.spoolDir=/usr/local/flume/tmp/TestDir
agent1.sources.source1.channels=channel1
agent1.sources.source1.fileHeader = false
agent1.sources.source1.interceptors = i1
agent1.sources.source1.interceptors.i1.type = timestamp
#配置sink1
#agent1.sinks.sink1.type=hdfs
#agent1.sinks.sink1.hdfs.path=hdfs://master:9000/library/flume
#agent1.sinks.sink1.hdfs.fileType=DataStream
#agent1.sinks.sink1.hdfs.writeFormat=TEXT
#agent1.sinks.sink1.hdfs.rollInterval=1
#agent1.sinks.sink1.channel=channel1
#agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d
#Spark Streaming 捕獲Flume的資料 SparkStreaming 監聽的host和port
#agent1.sinks.sink1.type=avro
#agent1.sinks.sink1.channel=channel1
#agent1.sinks.sink1.hostname=Master
#agent1.sinks.sink1.port=9999
#Spark Streaming主動從Flume取資料,按需來取
agent1.sinks.sink1.type=org.apache.spark.streaming.flume.sink.SparkSink
agent1.sinks.sink1.hostname=Master
agent1.sinks.sink1.port=9999
agent1.sinks.sink1.channel=channel1
#配置channel1
agent1.channels.channel1.type=file
agent1.channels.channel1.checkpointDir=/usr/local/flume/tmp/checkpointDir
agent1.channels.channel1.dataDirs=/usr/local/flume/tmp/dataDirs
4.配置streaming程式碼
SparkConf conf = new SparkConf().setMaster("local[4]").setAppName("FlumePollDate2SparkStreaming");
JavaStreamingContext jsc = new JavaStreamingContext(conf, Durations.seconds(30));
JavaReceiverInputDStream lines = FlumeUtils.createPollingStream(jsc, "master", 9999);