我正在尝试查看 Azure 事件中心中使用新的 Azure 事件数据生成器生成的数据 - 我说“新”,因为它是预览版。
当我尝试使用 Databricks 查看数据时,收到没有返回数据的消息
connectionString = 'Endpoint=sb://myspace.servicebus.windows.net/;SharedAccessKeyName=myaccesspolicy;SharedAccessKey=lfZTLixxxxxxxxxxxxxxxhYmIXVaNv9wRM+AEhJ3XsFc=;EntityPath=carlshub'
ehConf = {}
# For versions before 2.3.15, set the connection string without encryption
# ehConf['eventhubs.connectionString'] = connectionString
# For 2.3.15 version and above, the configuration dictionary requires that connection string be encrypted.
ehConf['eventhubs.connectionString'] = sc._jvm.org.apache.spark.eventhubs.EventHubsUtils.encrypt(connectionString)
df = spark \
.readStream \
.format("eventhubs") \
.options(**ehConf) \
.load()
df = df.withColumn("body", df["body"].cast("string"))
display(df)
但是,我在 Databricks 中的代码(上面)看不到数据
选择天气数据后,需要点击发送按钮生成数据。
确保您在源处发送数据。
输出
如果运行代码时发送的数据仍然没有结果,这是由于 enqueuedTime 导致的。
import json
from datetime import datetime as dt
endTime = dt.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
endingEventPosition = {
"offset": None,
"seqNo": -1,
"enqueuedTime": endTime,
"isInclusive": True
}
ehConf["eventhubs.startingPosition"] = json.dumps(endingEventPosition)
如果您先生成数据,然后使用上述选项运行代码,您将不会得到任何结果。
因此,请确保选择正确的选项并正确生成源数据。