Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3947#discussion_r22707632
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/streaming/MQTTWordCount.scala 
---
    @@ -42,25 +41,34 @@ object MQTTPublisher {
         StreamingExamples.setStreamingLogLevels()
     
         val Seq(brokerUrl, topic) = args.toSeq
    +    val tempDir = Utils.createTempDir()
    +    
    +    var client: MqttClient = null
     
         try {
    -      var peristance:MqttClientPersistence =new 
MqttDefaultFilePersistence("/tmp")
    +      val peristance:MqttClientPersistence = new 
MqttDefaultFilePersistence(tempDir.getAbsolutePath)
           client = new MqttClient(brokerUrl, MqttClient.generateClientId(), 
peristance)
    -    } catch {
    -      case e: MqttException => println("Exception Caught: " + e)
    -    }
     
    -    client.connect()
    +      client.connect()
    +
    +      val msgtopic: MqttTopic = client.getTopic(topic)
    +      val msgContent: String = "hello mqtt demo for spark streaming"
    +      val message: MqttMessage = new 
MqttMessage(msgContent.getBytes("utf-8"))
     
    -    val msgtopic: MqttTopic = client.getTopic(topic)
    -    val msg: String = "hello mqtt demo for spark streaming"
    +      while (true) {
    +        msgtopic.publish(message)
    +        println("Published data. topic: " + msgtopic.getName() + " 
Message: " + message)
    +      }
    +    }
    + 
    +    catch {
    +      case e: MqttException => println("Exception Caught: " + e)
    +    }
     
    -    while (true) {
    -      val message: MqttMessage = new 
MqttMessage(String.valueOf(msg).getBytes("utf-8"))
    -      msgtopic.publish(message)
    -      println("Published data. topic: " + msgtopic.getName() + " Message: 
" + message)
    +    finally {
    +      client.disconnect()
    +      Utils.deleteRecursively(tempDir)
    --- End diff --
    
    Do not use this. This Utils class is private to Spark, and should not be 
used in an example as other wont be able to access this class (unless they put 
their code in package org.apache.spark....).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to