mm1*_*112 8 apache-spark spark-structured-streaming
我正在编写一个测试应用程序,它消耗来自Kafka的topcis的消息,然后将数据推送到S3并进入RDBMS表(流程类似于此处所示:https://databricks.com/blog/2017/04/26/processing-data -in-apache-kafka-with-structured-streaming-in-apache-spark-2-2.html).所以我从Kafka读取数据然后:
所以我有点像:
Dataset<Row> df = spark
.readStream()
.format("kafka")
.option("kafka.bootstrap.servers", "host1:port1,host2:port2")
.option("subscribe", "topic1,topic2,topic3")
.option("startingOffsets", "earliest")
.load()
.select(from_json(col("value").cast("string"), schema, jsonOptions).alias("parsed_value"))
Run Code Online (Sandbox Code Playgroud)
(请注意我正在阅读多个Kafka主题).接下来我定义所需的数据集:
Dataset<Row> allMessages = df.select(.....)
Dataset<Row> messagesOfType1 = df.select() //some unique conditions applied on JSON elements
Dataset<Row> messagesOfType2 = df.select() //some other unique conditions
Run Code Online (Sandbox Code Playgroud)
现在为每个数据集我创建查询以开始处理:
StreamingQuery s3Query = allMessages
.writeStream()
.format("parquet")
.option("startingOffsets", "latest")
.option("path", "s3_location")
.start()
StreamingQuery firstQuery = messagesOfType1
.writeStream()
.foreach(new CustomForEachWiriterType1()) // class that extends ForeachWriter[T] and save data into external RDBMS table
.start();
StreamingQuery secondQuery = messagesOfType2
.writeStream()
.foreach(new CustomForEachWiriterType2()) // class that extends ForeachWriter[T] and save data into external RDBMS table (may be even another database than before)
.start();
Run Code Online (Sandbox Code Playgroud)
现在我想知道:
那些并行执行的查询(或者以FIFO顺序一个接一个地查询,我应该将这些查询分配给不同的调度程序池)?
将是那些并行执行的查询
是.这些查询将并行执行(每个查询都trigger没有指定,因此要尽可能快地运行它们).
在内部,当您start在DataStreamWriter上执行时,您创建一个StreamExecution依次创建所谓的守护进程microBatchThread(引自下面的Spark源代码):
val microBatchThread =
new StreamExecutionThread(s"stream execution thread for $prettyIdString") {
override def run(): Unit = {
// To fix call site like "run at <unknown>:0", we bridge the call site from the caller
// thread to this micro batch thread
sparkSession.sparkContext.setCallSite(callSite)
runBatches()
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在其自己的线程中查看名称中的每个查询:
stream execution thread for [prettyIdString]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1149 次 |
| 最近记录: |