import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.streaming.{Seconds, StreamingContext}

import scala.collection.mutable

object DStream_RDDqueue {
  def main(args: Array[String]): Unit = {
      val conf=new SparkConf().setAppName("RDD队列流").setMaster("local[2]")
      val ss=new StreamingContext(conf,Seconds(1))   //每一秒监听一次
      val RDDQueue=new mutable.SynchronizedQueue[RDD[Int]]
      val queueStream=ss.queueStream(RDDQueue)
    val result=queueStream.map(x=>(x%5,1)).reduceByKey(_+_)
        result.print(1000)
    ss.start()

    while(true){
         RDDQueue +=ss.sparkContext.makeRDD(1 to 100,2)
          Thread.sleep(2000)    //每2秒发一次数据
       }
   ss.stop()
  }

}

 

相关文章:

  • 2021-12-18
  • 2021-10-04
  • 2021-05-05
  • 2021-04-08
  • 2021-07-12
  • 2021-12-25
  • 2021-10-24
猜你喜欢
  • 2021-07-19
  • 2021-11-23
  • 2021-10-30
  • 2021-08-17
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案