<Spark Streaming><Flume><Integration>

來源:互聯網
上載者:User

標籤:exit   creat   flume   osi   play   receive   pid   maven   which   

Overview
  • Flume:一個分布式的,可靠的,可用的服務,用於有效地收集、彙總、移動大規模日誌資料
  • 我們搭建一個flume + Spark Streaming的平台來從Flume擷取資料,並處理它。
  • 有兩種方法實現:使用flume-style的push-based方法,或者使用自訂的sink來實現pull-based方法。
Approach 1: Flume-style Push-based Approach
  • flume被設計用來在Flume agents之間推資訊,在這種方式下,Spark Streaming安裝一個receiver that acts like an Avro agent for Flume, to which Flume can push the data.
General Requirement
  • 當你啟動flume + spark streaming應用時,該機器上必須運行一個Spark workers。
  • flume可以向該機器的某一個port push資料。
  • 基於這種push機制,streaming應用必須有一個receiver scheduled and listening on the chosen port.
Configuring Flume
  • 配置flume以向Avro sink發送資料
agent.sinks = avroSinkagent.sinks.avroSink.type = avroagent.sinks.avroSink.channel = memoryChannelagent.sinks.avroSink.hostname = <chosen machine‘s hostname>agent.sinks.avroSink.port = <chosen port on the machine>
View CodeConfiguring Spark Streaming Application
  1. Linking: 在maven項目中配置依賴
<dependency>    <groupId>org.apache.spark</groupId>    <artifactId>spark-streaming-flume-sink_2.10</artifactId>    <version>2.1.0</version></dependency>

  2. Programming:import FlumeUtils, 建立input DStream

 import org.apache.spark.streaming.flume._ val flumeStream = FlumeUtils.createStream(streamingContext, [chosen machine‘s hostname], [chosen port])
  • 注意:應該與cluster中的resourceManager使用同一個hostname,這樣的話資源分派可以匹配names,並在正確的機器上launch receiver
  • 一個簡單的Spark Streaming統計Flume event個數的demo代碼:
object FlumeEventCount {  def main(args: Array[String]) {    if (args.length < 2) {      System.err.println(        "Usage: FlumeEventCount <host> <port>")      System.exit(1)    }    StreamingExamples.setStreamingLogLevels()    val Array(host, IntParam(port)) = args    val batchInterval = Milliseconds(2000)    // Create the context and set the batch size    val sparkConf = new SparkConf().setAppName("FlumeEventCount")    val ssc = new StreamingContext(sparkConf, batchInterval)    // Create a flume stream    val stream = FlumeUtils.createStream(ssc, host, port, StorageLevel.MEMORY_ONLY_SER_2)    // Print out the count of events received from this server in each batch    stream.count().map(cnt => "Received " + cnt + " flume events." ).print()    ssc.start()    ssc.awaitTermination()  }}
View Code

 

<Spark Streaming><Flume><Integration>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.