【问题标题】:Trigger.Once with Azure Event HubsTrigger.Once 与 Azure 事件中心
【发布时间】:2020-06-16 16:34:42
【问题描述】:
【问题讨论】:
标签:
spark-structured-streaming
azure-eventhub
【解决方案1】:
最近有机会实现类似的东西:
我们的需要是;
- Databricks 将启动作业并从 eventthub 的上次运行偏移量读取一次
- 将数据保存到位置
- 结束作业,集群返回空闲/终止模式
这就是我们实现它的方式:
设置 eventthub conf:
val eventHubsConf: EventHubsConf = EventHubsConf(connStr).setMaxEventsPerTrigger(<someNumber>).setStartingPosition(EventPosition.fromOffset("@latest"))
从 eventthub 读取:
val incomingStream = spark.readStream.format("<your_evenhub_name>").options(eventHubsConf.toMap).load()
使用 Trigger.Once 编写
incomingStream.writeStream
.format("parquet").outputMode("append").trigger(Trigger.Once())
.partitionBy("<yourpartitionColumn>").option("truncate", false)
.option("checkpointLocation", "<yourcheckpointlocation>")
.option("path", "<youroutputdataDir>")
.start()