0

I want to create a MQTT stream which uses username and password for subscription. I am using apache-bahir for creating mqtt stream. When I used MQTTUtils.createStream() method, It only accepts ssc,brokerurl,topic, and StorageLevel as parameters. When I gave the username and password, it shows "Can not 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/

This page is I refereed for the implementation.

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")

Error Message is Cannot Resolve Symbol MQTTUtils.createStream()

Fudgy
  • 165
  • 2
  • 10
Ashok v
  • 77
  • 1
  • 8

2 Answers2

0

Try to this:

 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()

you have all the information in Github

0

Using JavaStreamingContext we can solve this problem

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()
Ashok v
  • 77
  • 1
  • 8