我想创建一个MQTT流,它使用用户名和密码进行订阅。我正在使用apache-bahir来创建mqtt流。当我使用MQTTUtils.createStream()方法时,它只接受ssc、brokerurl、topic和StorageLevel作为参数。当我提供用户名和密码时,它显示"Can‘t resolve symbol createStream().
val lines = MQTTUtils.createStream(ssc, brokerUrl, topic, storageLevel, clientId, username, password, cleanSession, qos, connectionTimeout, keepAliveInterval, mqttVersion)https://bahir.apache.org/docs/spark/2.3.0/spark-streaming-mqtt/
这个页面是我推荐的实现。
val sc = new SparkContext()
val ssc = new StreamingContext(sc,Seconds(10))
val stream = MQTTUtils.createStream(ssc,"broker.mqttdashboard.com","tag_topic",StorageLevel.DISK_ONLY,"clientid","username","password")错误消息是无法解析Symbol MQTTUtils.createStream()
发布于 2019-11-19 23:32:50
试着这样做:
val spark = SparkSession
.builder()
.appName("app")
.config("spark.master", "local[*]")
.getOrCreate()
val lines = spark.readStream
.format("org.apache.bahir.sql.streaming.mqtt.MQTTStreamSourceProvider")
.option("username", username)
.option("password", password)
.option("topic", topic)
.option("brokerUrl",brokerUrl )
.load()所有信息都在Github中
发布于 2019-11-20 17:26:12
使用JavaStreamingContext我们可以解决这个问题
val jssc = new JavaStreamingContext(sc,Seconds(2))
val clientId = MqttClient.generateClientId()
val stream = MQTTUtils.createPairedByteArrayStream(jssc,brokerUrl,topic,clientId,username,password,true)
stream.print()
jssc.start()
jssc.awaitTermination()https://stackoverflow.com/questions/57238429
复制相似问题