spark streaming 官网文档---notes(1)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40042143/article/details/84769552

StreamingContex的初始化

两种方式:

第一种:从SparkConf对象中创建

import org.apache.spark._
import org.apache.spark.streaming._

val conf = new SparkConf().setAppName(appName).setMaster(master)
val ssc = new StreamingContext(conf, Seconds(1))

第二种:从已经存在的SparkContex对象中创建

import org.apache.spark.streaming._

val sc = ...                // existing SparkContext
val ssc = new StreamingContext(sc, Seconds(1))

创建StreamingContext后需要做以下操作:

  • 定义输入源 input sources ---创建input DStreams
  • 定义流的相关计算---应用DStreams的transformation and output operations
  • 通过streamingContext.start()接收和处理数据
  • 等待处理完成(手动停止或报错)---streamingContex.awaitTermination()
  • 手动停止处理进程--streamingContext.stop()

猜你喜欢

转载自blog.csdn.net/weixin_40042143/article/details/84769552
今日推荐