【发布时间】:2018-08-16 13:57:01
【问题描述】:
我希望从 JSON 文件中读取结构化流,处理数据并将数据写入 Kafka 和 Parquet 接收器。我在下面看到相同的示例代码
datasetOfString.writeStream.foreach(new ForeachWriter[String] {
def open(partitionId: Long, version: Long): Boolean = {
// open connection
}
def process(record: String) = {
// write string to connection
}
def close(errorOrNull: Throwable): Unit = {
// close the connection
}
})
但是我怎样才能在这里传递多个作家呢?像下面这样吗?
datasetOfString.writeStream.foreach(kafkaWriter).start()
datasetOfString.writeStream.foreach(parquetWriter).start()
如果我这样做,那么使用 foreach 作家的目的是什么?只是为了在写作时进行更多控制吗?
【问题讨论】:
标签: scala apache-spark apache-spark-sql spark-structured-streaming