gpt4 book ai didi

azure - 如何从azure eventhub获取记录到databricks

转载 作者:行者123 更新时间:2023-12-03 03:54:42 25 4
gpt4 key购买 nike

我正在使用社区添加的数据 block 。我尝试以下代码但没有收到任何记录:

var streamingSelectDF = 
streamingInputDF
.select(get_json_object(($"body").cast("string"), "$.id").alias("id"),get_json_object(($"body").cast("string"), "$.CarName").alias("CarName"))

streamingSelectDF.writeStream.outputMode("append").format("console").option("truncate", false).start().awaitTermination()

最佳答案

您能否检查事件中心是否收到任何消息?

如果没有,您可以向 eventhub 发送一些示例事件,看看它是否接收到这些事件。

从事件中心读取数据并将数据打印到控制台的示例代码。

// Build connection string with the above information
val namespaceName = "<EVENT HUBS NAMESPACE>"
val eventHubName = "<EVENT HUB NAME>"
val sasKeyName = "<POLICY NAME>"
val sasKey = "<POLICY KEY>"
val connStr = new com.microsoft.azure.eventhubs.ConnectionStringBuilder()
.setNamespaceName(namespaceName)
.setEventHubName(eventHubName)
.setSasKeyName(sasKeyName)
.setSasKey(sasKey)

val customEventhubParameters =
EventHubsConf(connStr.toString())
.setMaxEventsPerTrigger(5)

val incomingStream = spark.readStream.format("eventhubs").options(customEventhubParameters.toMap).load()

incomingStream.writeStream.outputMode("append").format("console").option("truncate", false).start().awaitTermination()

您可以引用此链接了解更多详情: https://learn.microsoft.com/en-in/azure/databricks/scenarios/databricks-stream-from-eventhubs

关于azure - 如何从azure eventhub获取记录到databricks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65006664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com