scala - S3 目录上的 Spark Streaming

标签 scala amazon-web-services amazon-s3 apache-spark spark-streaming

因此,我有数千个事件通过 Amazon Kinesis 流式传输到 SQS,然后转储到 S3 目录中。大约每 10 分钟,就会创建一个新的文本文件,将 Kinesis 中的数据转储到 S3 中。我想设置 Spark Streaming,以便它将转储到 S3 的新文件流式传输。现在我有

import org.apache.spark.streaming._
val currentFileStream = ssc.textFileStream("s3://bucket/directory/event_name=accepted/")
currentFileStream.print
ssc.start()

但是,Spark Streaming 不会接收转储到 S3 中的新文件。我认为这与文件写入要求有关:
The files must have the same data format.
The files must be created in the dataDirectory by atomically moving or renaming them into the data directory.
Once moved, the files must not be changed. So if the files are being continuously appended, the new data will not be read.

为什么 Spark 流不能接收新文件?是因为 AWS 在目录中创建文件而不是移动它们吗?我如何确保 Spark 接收到正在转储到 S3 中的文件?

最佳答案

为了流式传输 S3 存储桶。您需要提供 S3 存储桶的路径。它将从该存储桶中的所有文件中流式传输所有数据。然后每当在此存储桶中创建 w 新文件时,它将被流式传输。如果您将数据附加到之前读取的现有文件,则不会读取这些新更新。

这是一小段有效的代码

import org.apache.spark.streaming._

val conf = new SparkConf().setAppName("Simple Application").setMaster("local[*]")      
val sc = new SparkContext(conf)
val hadoopConf=sc.hadoopConfiguration;
hadoopConf.set("fs.s3.impl", "org.apache.hadoop.fs.s3native.NativeS3FileSystem")
hadoopConf.set("fs.s3.awsAccessKeyId",myAccessKey)
hadoopConf.set("fs.s3.awsSecretAccessKey",mySecretKey)

//ones above this may be deprecated?
hadoopConf.set("fs.s3n.awsAccessKeyId",myAccessKey)
hadoopConf.set("fs.s3n.awsSecretAccessKey",mySecretKey)

val ssc = new org.apache.spark.streaming.StreamingContext(
  sc,Seconds(60))
val lines = ssc.textFileStream("s3n://path to bucket")
lines.print()

ssc.start()             // Start the computation
ssc.awaitTermination()  // Wait for the computation to terminate

希望它会有所帮助。

关于scala - S3 目录上的 Spark Streaming,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30994401/

相关文章:

mysql - 在光滑的操作中使用 scala 集合等价物是否有害?

scala - "!"在 Scala 中是什么意思?

timestamp - SimpleDB 插入时的时间戳

amazon-web-services - 无法为 AWS Data Migration Service 导入证书

hadoop - s3n/s3a如何管理文件?

scala - SortedSet 为保留(排序)顺序的 seq

scala - 防止在 Scala 中导入未经授权的类

amazon-web-services - 如何通过 AWS CDK 设置 DataDog 警报?

python - 将 Amazon S3 与 Heroku、Python 和 Flask 结合使用

node.js - 如何在 aws s3 中指定索引文档?