Spark Streaming的foreachRDD把处理后的数据写入外部存储系统中

来源:互联网 发布:遗传算法的matlab程序 编辑:程序博客网 时间:2024/05/17 12:06

1.代码

 

dstream.foreachRDD { rdd =>

  rdd.foreachPartition { partitionOfRecords =>

    // ConnectionPool is a static, lazily initialized pool of connections

    val connection = ConnectionPool.getConnection()

    partitionOfRecords.foreach(record => connection.send(record))

    ConnectionPool.returnConnection(connection)  // return to the pool for future reuse

  }}

 

0 0
原创粉丝点击