Spark 3.0 - 从 MQTT 流中读取数据

问题描述

我想将数据流从基于 mosquitto 的 MQTT 主题读取到我的 Spark 3.0 应用程序中。我通过以下方式尝试使用 Bahir 库:

Dataset<Row> df = sparkSession
           .readStream()
           .format("org.apache.bahir.sql.streaming.mqtt.MQTTStreamSourceProvider")
           .option("topic","mytopic")
           .load("tcp://localhost:1883");

不幸的是这失败了:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/sql/sources/v2/StreamWriteSupport

显然这仅适用于 2.x Spark。知道如何使用 Spark 3(或使用不同的库)使其工作吗?

解决方法

查看可用的库 here,(see picture below),看起来该库已可用于 Spark 3.x。另外,我不知道有任何其他公共图书馆。

enter image description here